Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to pass a groupbox from a class to other class

How to pass a groupbox from a class to other class

Scheduled Pinned Locked Moved C#
tutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TALHAKOSEN
    wrote on last edited by
    #1

    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...

    T 1 Reply Last reply
    0
    • T TALHAKOSEN

      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...

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      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#)

      T 1 Reply Last reply
      0
      • T Tom Deketelaere

        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#)

        T Offline
        T Offline
        TALHAKOSEN
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups