Help with simple user control
-
:confused: I am reasonably competent with C# (please note that "reasonably" is a very subjective term), but don't have much (read: any) experience building user controls. The (very simple) user control I am having problems with contains two panels, three labels and a combobox. Which of the two panels is visible depends on whether the control is currently in edit mode. Currently I have the control go into edit mode and thus change which panel is visible when any control in the user control is clicked. I am looking for a clean way of doing the opposite: I can't seem to find an event that will fire when a user clicks on another part of the form. Therefore, the control still looks like it's being edited while the user is off doing something else entirely. I'm sure the answer will be sufficiently simple so as to make me feel foolish for asking, but it's really starting to irritate me. Any help would be appreciated. Charlie Here I am. Love me.
-
:confused: I am reasonably competent with C# (please note that "reasonably" is a very subjective term), but don't have much (read: any) experience building user controls. The (very simple) user control I am having problems with contains two panels, three labels and a combobox. Which of the two panels is visible depends on whether the control is currently in edit mode. Currently I have the control go into edit mode and thus change which panel is visible when any control in the user control is clicked. I am looking for a clean way of doing the opposite: I can't seem to find an event that will fire when a user clicks on another part of the form. Therefore, the control still looks like it's being edited while the user is off doing something else entirely. I'm sure the answer will be sufficiently simple so as to make me feel foolish for asking, but it's really starting to irritate me. Any help would be appreciated. Charlie Here I am. Love me.
You should be able to handle the
LostFocus
event (orLeave
event) of theUserControl
itself, since theGotFocus
andEnter
events bubble up. This way, when any control in yourUserControl
(and thus theUserControl
itself) loose focus, you can switch your panels' visibility.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
You should be able to handle the
LostFocus
event (orLeave
event) of theUserControl
itself, since theGotFocus
andEnter
events bubble up. This way, when any control in yourUserControl
(and thus theUserControl
itself) loose focus, you can switch your panels' visibility.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Thank you for the response. It turned out that by making the panel visible, but not giving focus to any of the controls on it, that the original control still had the focus and as such, no LostFocus event would fire :-O Your reinforcement that I was handling the correct event allowed me to stop looking araound aimlessly and figure out what the problem was. Thank you. Charlie Here I am. Love me.