How to pass a groupbox from a class to other class
-
they are in a different class named baglanti public GroupBox gb; public void gbColor(GroupBox gbT) { gb = gbT; gb.MouseClick += new MouseEventHandler(gb_click); } private void gb_click(object sender, EventArgs e) { gb.BackColor = Color.Red; } in other class i use this to add gb_click event to the groupboxes clsBgl.gbColor(groupBox1); clsBgl.gbColor(groupBox2); clsBgl.gbColor(groupBox3); it always execute the lastone, when i click on groupbox3 its color is changing but others stay same. thanx for your helps..
thanks for everything i have...
-
they are in a different class named baglanti public GroupBox gb; public void gbColor(GroupBox gbT) { gb = gbT; gb.MouseClick += new MouseEventHandler(gb_click); } private void gb_click(object sender, EventArgs e) { gb.BackColor = Color.Red; } in other class i use this to add gb_click event to the groupboxes clsBgl.gbColor(groupBox1); clsBgl.gbColor(groupBox2); clsBgl.gbColor(groupBox3); it always execute the lastone, when i click on groupbox3 its color is changing but others stay same. thanx for your helps..
thanks for everything i have...
TALHAKOSEN wrote:
clsBgl.gbColor(groupBox1); clsBgl.gbColor(groupBox2); clsBgl.gbColor(groupBox3);
you are overwriting the variable (gb) so the behavior is expected instead create a new instance of the class for every groupbox gb1 = new clsgbl gb1.gbcolor(groupbox1) gb2 = new clsgbl gb2.gbcolor(groupbox2) gb3 = new clsgbl gb3.gbcolor(groupbox3) (not shure about the syntax been a while since I done c#)
-
TALHAKOSEN wrote:
clsBgl.gbColor(groupBox1); clsBgl.gbColor(groupBox2); clsBgl.gbColor(groupBox3);
you are overwriting the variable (gb) so the behavior is expected instead create a new instance of the class for every groupbox gb1 = new clsgbl gb1.gbcolor(groupbox1) gb2 = new clsgbl gb2.gbcolor(groupbox2) gb3 = new clsgbl gb3.gbcolor(groupbox3) (not shure about the syntax been a while since I done c#)
Thx for your help and i found how to to do that exactly public void gbRenk( GroupBox gb) { gb.MouseClick += new MouseEventHandler(gb_renkAl); } private void gb_renkAl(object sender, EventArgs e) { **((GroupBox)sender).**BackColor = Color.Red; }
thanks for everything i have...