Windows Develop Bookmark and Share   
 index > Windows Forms Designer > connection between two forms
 

connection between two forms

hello everybody i have a problem
i have two forms.Inside the first form i have a textbox and in the second a label.I want when inside the textbox someone writes "1234" then it opens the second form and the label in the second form change its name to "nikos" for example. can anyone help. windows form application c#
2000sam  Wednesday, February 11, 2009 8:52 PM
Hi 2000sam,

Please try the following code.

In form1:
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
this.textBox1.TextChanged+=newEventHandler(textBox1_TextChanged);
}
voidtextBox1_TextChanged(objectsender,EventArgse)
{
if(this.textBox1.Text=="1234")
{
Form2f=newForm2();
f.Lable1.Text="Nikos";
f.ShowDialog();
}
}
}


In form2:
publicpartialclassForm2:Form
{
publicForm2()
{
InitializeComponent();
}
publicLabelLable1
{
get
{
returnthis.label1;
}
set
{
this.label1=value;
}
}
}

If you have any problem, please feel free to let me know.

Best regards,
Bruce Zhou



Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer by2000sam Friday, February 13, 2009 12:50 PM
  •  
Bruce.Zhou  Friday, February 13, 2009 5:48 AM
Hi 2000sam,

Please try the following code.

In form1:
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
this.textBox1.TextChanged+=newEventHandler(textBox1_TextChanged);
}
voidtextBox1_TextChanged(objectsender,EventArgse)
{
if(this.textBox1.Text=="1234")
{
Form2f=newForm2();
f.Lable1.Text="Nikos";
f.ShowDialog();
}
}
}


In form2:
publicpartialclassForm2:Form
{
publicForm2()
{
InitializeComponent();
}
publicLabelLable1
{
get
{
returnthis.label1;
}
set
{
this.label1=value;
}
}
}

If you have any problem, please feel free to let me know.

Best regards,
Bruce Zhou



Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer by2000sam Friday, February 13, 2009 12:50 PM
  •  
Bruce.Zhou  Friday, February 13, 2009 5:48 AM
thank you Bruce.Zhou!!!
2000sam  Friday, February 13, 2009 12:51 PM
I hope no one minds if I bookmark this thread for my own reference, with the code helpfully (for me) converted to VB.

1 PublicPartialClassForm1
2 InheritsForm
3 PublicSubNew()
4 InitializeComponent()
5 AddHandlerMe.textBox1.TextChanged,AddressOftextBox1_TextChanged
6 EndSub
7
8 PrivateSubtextBox1_TextChanged(ByValsenderAsObject,ByValeAsEventArgs)
9 IfMe.textBox1.Text="1234"Then
10 DimfAsNewForm2()
11 f.Lable1.Text="Nikos"
12 f.ShowDialog()
13 EndIf
14 EndSub
15 EndClass
16
17 PublicPartialClassForm2
18 InheritsForm
19 PublicSubNew()
20 InitializeComponent()
21 EndSub
22 PublicPropertyLable1()AsLabel
23 Get
24 ReturnMe.label1
25 EndGet
26 Set(ByValvalueAsLabel)
27 Me.label1=value
28 EndSet
29 EndProperty
30 EndClass
reachrishikh  Friday, February 13, 2009 4:23 PM

You can use google to search for other answers

Custom Search

More Threads

• report load failed in another PC
• DatagridView Columns Property
• Custom Collection Editor - how to block the up and down buttons ?
• Subcribing to a parent event from a child....form / usercontrol...
• How to stop designer adding columns when i build the project
• Cannot Open File
• Menu Button (outside of a toolbar)
• Transparent Windows Forms controls
• Windows Form Designer Fails to Load
• UITypeEditor, Component get list of controls