C# - Events not triggering
-
Hi, A quick question on using events in c#. I have a groupbox on a winform. In that groupbox are a number of textboxes, buttons etc. In order to keep the screen clean, when the mouse is not in the groupbox, some of the buttons are hidden. I use the mouseEnter and mouseLeave events to trigger this. The problem I have is that when a button appears and I click on it, it doesn't trigger the Click event. If I disable the hiding/making visible events then it all works fine. Any ideas? Many thanks, John.
-
Hi, A quick question on using events in c#. I have a groupbox on a winform. In that groupbox are a number of textboxes, buttons etc. In order to keep the screen clean, when the mouse is not in the groupbox, some of the buttons are hidden. I use the mouseEnter and mouseLeave events to trigger this. The problem I have is that when a button appears and I click on it, it doesn't trigger the Click event. If I disable the hiding/making visible events then it all works fine. Any ideas? Many thanks, John.
Can you show the code that is hiding/showing the buttons? There should be also some code to hook up the click events, if you reattach the click event after showing the button it all should work fine :)
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson My blog
-
Can you show the code that is hiding/showing the buttons? There should be also some code to hook up the click events, if you reattach the click event after showing the button it all should work fine :)
WM. What about weapons of mass-construction? "What? Its an Apple MacBook Pro. They are sexy!" - Paul Watson My blog
Hi Willem, In the designer script, I have the following events defined for the groupbox: this.Conduit_Info_Group.MouseLeave += new System.EventHandler(this.Conduit_Info_Group_Exit); this.Conduit_Info_Group.MouseEnter += new System.EventHandler(this.Conduit_Info_Group_Enter); For the specific button, here is the defined event: this.Conduit_AuthorisedAmount_Graph.Click += new System.EventHandler this.Conduit_AuthorisedAmount_Graph_Click); Here are the above 3 methods: private void Conduit_Info_Group_Enter(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = true; } private void Conduit_Info_Group_Exit(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = false; } private void Conduit_AuthorisedAmount_Graph_Click(object sender, EventArgs e) { } I have also tried changing the enter and exit events as follows: private void Conduit_Info_Group_Enter(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = true; this.Conduit_AuthorisedAmount_Graph.Click += new System.EventHandler(this.Conduit_AuthorisedAmount_Graph_Click); } private void Conduit_Info_Group_Exit(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = false; this.Conduit_AuthorisedAmount_Graph.Click -= new System.EventHandler(this.Conduit_AuthorisedAmount_Graph_Click); } In other words, I've reattached the event after showing the button and removed the event after hiding it, but it doesn't make a difference. Another thing I've tried is removing the event MouseEnter once I've entered the groupbox and reattaching it after I leave. My thinking was that MouseEnter events were swamping the message queue and my button press event was getting lost, but still it wouldn't work! Some days, VB6 just seems much simpler :wtf: Many thanks, John.
-
Hi Willem, In the designer script, I have the following events defined for the groupbox: this.Conduit_Info_Group.MouseLeave += new System.EventHandler(this.Conduit_Info_Group_Exit); this.Conduit_Info_Group.MouseEnter += new System.EventHandler(this.Conduit_Info_Group_Enter); For the specific button, here is the defined event: this.Conduit_AuthorisedAmount_Graph.Click += new System.EventHandler this.Conduit_AuthorisedAmount_Graph_Click); Here are the above 3 methods: private void Conduit_Info_Group_Enter(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = true; } private void Conduit_Info_Group_Exit(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = false; } private void Conduit_AuthorisedAmount_Graph_Click(object sender, EventArgs e) { } I have also tried changing the enter and exit events as follows: private void Conduit_Info_Group_Enter(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = true; this.Conduit_AuthorisedAmount_Graph.Click += new System.EventHandler(this.Conduit_AuthorisedAmount_Graph_Click); } private void Conduit_Info_Group_Exit(object sender, EventArgs e) { this.Conduit_AuthorisedAmount_Graph.Visible = false; this.Conduit_AuthorisedAmount_Graph.Click -= new System.EventHandler(this.Conduit_AuthorisedAmount_Graph_Click); } In other words, I've reattached the event after showing the button and removed the event after hiding it, but it doesn't make a difference. Another thing I've tried is removing the event MouseEnter once I've entered the groupbox and reattaching it after I leave. My thinking was that MouseEnter events were swamping the message queue and my button press event was getting lost, but still it wouldn't work! Some days, VB6 just seems much simpler :wtf: Many thanks, John.
I wouldn't bother with detaching/reattaching; just attach it as usual and leave it.