forms

web4

Member
Joined
Mar 28, 2009
Messages
16
Programming Experience
Beginner
hi i'm new to vb.net....umm
i just want to ask that is it possible to change the form of it's label??

for example i have a form1 and form 2...
then in form2 i have a label1 and label2...
if the value of the variable in the form1(enter by the user through textbox) is equal to one then the label2 in form2 would be invisible...

how could i do that?

because i use form load to load all the default settings in form2 then i put some "if else" in formload in form2 hoping that i could get that kind of program.

...please help me..

thanks
 
This is a simplified code for two forms. If the user enters "OK" in the Form1 textbox, it will change the text of the label in Form2 to "OK." The following code is placed in Form1.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form2.Show()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text = "OK" Then
Form2.Label1.Text = "OK"
End If
End Sub
 
another question about forms....umm how could i assign variables in one form to another? cause i'd do like what you post in changing the text of label in another form...my code goes like this f.lname = LastName (in that code f is form2 and i declare it on top like this dim f as form2 then..f = new form2...and the lname is a variable in that form2) but when i test that program the variable in the form2 is null(lname which i've pass the value LastName) i hope you get my question thanks again...
 
Declare the variable with the Public keyword instead of Dim in Form1. When using it in Form2, use the fully-qualified name; for example: Form1.myvariable

Alternatively, you can declare the variable using Public in a new Module. That will make it accessible to all the forms without needing to qualify it.
 
umm solitaire...i don't know how to use module...is there a good link that you can recommend for me so that i could learn how to use module? or you can post a code for me demonstrating how to use module...thanks
 
On the menu bar, click Project and select Add Module.

A new window will open with a list of installed templates. Select Module and click the Add button.

A new edit window will open with the Module Module1 statement on top. It will also be listed in the Solution Explorer window.

Now declare the variable starting with Public instead of Dim. That variable will be recognized by all the forms in the project.
 
Back
Top