VB.Net - Manage errors label - vb.net

I'm working on visual studio 2015 and I'm working on a classic subscribing form.
I want to generate error labels when the user type wrong password, the wrong pseudo, etc. But I can work on it myself.
But when I write those error labels and set their visible at false in "Dev mode", I have to juxtapose those labels if I want my labels at the same place, and it's not what I want when I have many errors to manage on one textBox for example.
Is there a solution to gererate those labels, without write them before playing with hide() or show() ?
Here is the screenshot in order to illustrate my problem.
It's not really a problem itself, but It's not practical when I'm develop many errors.
Sorry for my english, I hope you understood my problem, I can give you more details =)
Have a nice day full of code !

Here the button code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "Password" Then
Label2.Text = "Your answer is wrong"
End If
End Sub
This is what it looks like:

Related

How should I reset my application using vb2008 except for the last form?

So, I made an application which composes several forms. It contains saving scores at the end of the game(form). However, when I try to reset the game, it resets all the data with this code:
Private Sub ResetDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResetDataToolStripMenuItem.Click
Application.Restart()
Me.Refresh()
I only want to reset all forms except for the scoretable form which is the last form. Can you give me the easiest way to solve my problem?
P.S I am a newbie for this. Please help me guys. This will serve as my quarterly exam. I need to pass.

How to get more than one parent control in form

Newbie here :)
In order to achieve a transparency-type effect for pictureboxcharacter1 on the background, I have set pictureboxbackground1 as its parent.
this works fine.
For the second picturebox (on the same form) I tried the same thing and set pictureboxbackground2 as its parent so it would look transparent over pictureboxbackground2. However when I debug the application pictureboxcharacter2 disappears and only pictureboxbackground2 is visible.
the code I have is:
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.pictureboxcharacter1.Parent = Me.pictureboxbackground1
Me.pictureboxcharacter2.Parent = Me.pictureboxbackground2
End Sub
Really strange: if I put pictureboxcharacter2 on pictureboxbackground1 in the designer tab, while debugging it shows up on picturebackground2 and transparent (like how I wanted it to be)??
Does anyone know what's going on at all?
Please I'm NEED any help I could get
Is pictureboxcharacter1 and pictureboxcharacter2 one over other ? If so try making the one be other's parent.
Have a play with bring to front option and see if that works.

Weird functionality when using ScriptManager.RegisterStartupScript

I'm having this weird problem using the ScriptManager.RegisterStartupScript. Basically what I'm trying to accomplish when I click a button control, it goes back to the server, checks to see if any errors, and what I want to happen is that if there are any errors, want to use a popup box. The button control is inside an update panel. I thought the easiest way to accomplish this was to use a javascript alert box. So I finally got it working but when the alert box comes up it messes up my menu control until the alert box is going then its ok. Its kinda of hard to explain so I have insert a image to show you guys whats going on once the button is clicked. I dont know how to fix or whats going on, if someone could point me into the right direction. Also he my code im using.
Protected Sub btnPlan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPlan.Click
'Dim sb As New System.Text.StringBuilder
sb.Append("<script language='javascript'>")
sb.Append("alert(' No data in the database ');")
sb.Append("</script>")
If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
ScriptManager.RegisterStartupScript(UpdatePanel5, Me.GetType(), "JSScript", sb.toString(), True)
End If
You may try to use RegisterClientScriptBlock:
Protected Overrides Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs)
MyBase.Page_Load(sender, e)
Try
If Not ScriptManager.IsInAsyncPostBack Then
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertScript", "<script type='text/javascript' language='javascript'>function YourAlert(){alert(' No data in the database ');}</script>")
EndIf
Catch ex As Exception
End Try
End Sub
Thanks for all your suggestion. I skinned this a different way and got it to work the way I wanted. What i did was put the message in a hidden textbox and used jquery to ensure that the page was already load then alert the message if needed.

Printing Active Child Form

I am new to VB and today I programmed my first form that uses parent and child forms. The assignment asks to "print the active child form" and I am a little stuck. So far this semester printing has not really been a big part of the assignments and I can't seem to find much in the book.
The way the assignment is coded is in the parent form there is a menu strip and I created a print click event in the menu. I guess I'm unsure where to start to make this be able to print just the active child form. My extent of printing my forms has been been dropping a printform from the VB powerpacks and then coding the form to print to preview.
Can someone point me in the right direction? Any hint would be huge so I know at least what to look for in the book. This is for homework.
I found the answer to my own question. Here is a snipped of the code I used. I ended up keeping my printform from the powerpack I just was hung up on how to tell the program to find the active form.
Here is the code I used.
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click, PrintToolStripButton.Click
If Me.ActiveMdiChild Is Nothing Then
Return
End If
PrintForm1.Form = Me.ActiveMdiChild
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub

Lost Focus problems

I use the LostFocus Event in vb.net to check the validity of a field for the name.
After this field a have another one which is the for the password validity, and i'm handilg the same event in order to check the password.
My problem comes when i run the (name) lost focus, runs the code inside the sub and after that automatically goes to the password_lostfocus which brings me alot of troubles.
That happens even i use the error provider which works fine and bring to me the error with the red flashing.After that i put the command (name_textbox.focus), which logically has to bring the control in the name_textbox.. But NO.. the control goes to the Password_textbox sub automatically.
Please see my sub
Private Sub UsernameTextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles UsernameTextBox.LostFocus
Select Case DB_Access.IfExistUser(UsernameTextBox.Text, sender, e)
Case True
PasswordTextBox.Focus()
Case False
ErrorProvider1.SetError(UsernameTextBox, "Ο χρήστης ΔΕΝ υπάρχει παρακαλώ καλέστε τον Administrator")
Beep()
UsernameTextBox.Text = ""
UsernameTextBox.Focus()
End Select
End Sub
Please if anyone have seen this issue and face it, assist me.
Excuse me for some Greek characters they are meaningless, they are comments
Well finally i found that.
In order to handle the Login Form as it give it from visual studio 2010 you need to do it in only one sub (Lost Focus) and that is only the password_LostFocus.
I believe the particular form is meant to be like that.
Any way i solve the issue and if anybody needs assistance on that just "asc a question"