How to pass values from 1 form to another in c# windows?
How to pass values from 1 form to another in c# windows?
Collapse
X
-
There are many ways to do that. Here are some examples:
You can declare a public static method on the first form that sets a static class attribute and call the method from the second form. Something like this:
##### Form that receive values
Code:public partial class Form2 : Form { static string name { get; set; } public Form2() { InitializeComponent(); } public static void setName(string pName) { name = pName; } } ##### Form that send values public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2.setName("Sfreak"); } }
Better than this you can implement an Observer pattern that manages the first form using an Interface between them.Comment
Comment