Get Control from another form
-
Hi, i'm having a problem how to get a control from form 1 to form 2..for example: i want gridview name dgvBlaBla from form1 can be access from form 2 ?_? Can Anyone Help Me..I'm sorry i'm beginner in C# Regard, TCim
#1. Lets say there are two forms (form1, form2) in your application. you put one button called button1 in form2. You wanna get the control (button1) of form2 from form1. Add one public property which is returned the control that you required in form2 eg:
public Button Button1 { get { return button1; } }
Then, you can access this control from form1. eg:Form2 obj = new Form2(); MessageBox.Show(obj.Button1.Text);
There are another way to get the control from other form or assembles. I'm not gonna mention here. If you are interest about this, please "Reflection" class from MSDN or google. Hope it helps.Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)
-
Hi, i'm having a problem how to get a control from form 1 to form 2..for example: i want gridview name dgvBlaBla from form1 can be access from form 2 ?_? Can Anyone Help Me..I'm sorry i'm beginner in C# Regard, TCim
You've got an answer already, but I'm asking myself why you want to do this? because I think there is a bit of a design problem here (information hiding? encapsulation?)
-^-^-^-^-^- no risk no funk
-
#1. Lets say there are two forms (form1, form2) in your application. you put one button called button1 in form2. You wanna get the control (button1) of form2 from form1. Add one public property which is returned the control that you required in form2 eg:
public Button Button1 { get { return button1; } }
Then, you can access this control from form1. eg:Form2 obj = new Form2(); MessageBox.Show(obj.Button1.Text);
There are another way to get the control from other form or assembles. I'm not gonna mention here. If you are interest about this, please "Reflection" class from MSDN or google. Hope it helps.Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)