C# Forms: Capture scroll event in a usercontrol with only static checkboxes.
-
Hi, I have made a C# forms application. In there i use a usercontrol that dynamicly puts a list of checkboxes onto the usercontrol. Next to the checkboxes is a scrollbar. If you move the scrollbar the checkboxes will be set onto the selection that is pointed out by the scrollbar. So the Text and Checked state of the checkboxes get updated to the position in the entire list. (in short, i've made my own ListBox with checkboxes) My problem is that i cannot capture the scroll event of the mouse from checkboxes(using the hardware scrollbutton). The scroll event of the usercontrol itself doesn't get triggerd because of the checkboxes are on top of it. And the checkboxes itself do not have a scroll event. How can i solve this? Greetz Willem
-
Hi, I have made a C# forms application. In there i use a usercontrol that dynamicly puts a list of checkboxes onto the usercontrol. Next to the checkboxes is a scrollbar. If you move the scrollbar the checkboxes will be set onto the selection that is pointed out by the scrollbar. So the Text and Checked state of the checkboxes get updated to the position in the entire list. (in short, i've made my own ListBox with checkboxes) My problem is that i cannot capture the scroll event of the mouse from checkboxes(using the hardware scrollbutton). The scroll event of the usercontrol itself doesn't get triggerd because of the checkboxes are on top of it. And the checkboxes itself do not have a scroll event. How can i solve this? Greetz Willem
If I have interpreted your question correctly, you are saying that using the scrollwheel on your mouse does not cause the panel to scroll. If I have misunderstood then please disregard the rest of this message. There are several controls in Visual Studio that suffer from this problem. Sometimes, but not always, this is caused because the control does not have focus. The solution in those cases is to handle the
MouseEnter
event to give the control focus.private void myUserControl_MouseEnter(object sender, EventArgs e)
{
myUserControl.Focus(); //allows the mouse wheel to work after the panel has had the mouse move over it
}If this doesn't work immediately, then I am probably wrong about the cause. Good luck! :)
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
-
If I have interpreted your question correctly, you are saying that using the scrollwheel on your mouse does not cause the panel to scroll. If I have misunderstood then please disregard the rest of this message. There are several controls in Visual Studio that suffer from this problem. Sometimes, but not always, this is caused because the control does not have focus. The solution in those cases is to handle the
MouseEnter
event to give the control focus.private void myUserControl_MouseEnter(object sender, EventArgs e)
{
myUserControl.Focus(); //allows the mouse wheel to work after the panel has had the mouse move over it
}If this doesn't work immediately, then I am probably wrong about the cause. Good luck! :)
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
This was my first solution and it doesn't work. When i do this my usercontrol will get the focus(the mouseenter event gets fired), but it doesn't fire the scroll event after that. I think this is because the checkboxes override the foces when hovering over it, I think this because the checkbox "lights up" when you hover over it(I use windows 7). So i think you understood my question right, but the solution doesn't work.
-
This was my first solution and it doesn't work. When i do this my usercontrol will get the focus(the mouseenter event gets fired), but it doesn't fire the scroll event after that. I think this is because the checkboxes override the foces when hovering over it, I think this because the checkbox "lights up" when you hover over it(I use windows 7). So i think you understood my question right, but the solution doesn't work.
OK. Sorry. :( Keep trying though. BTW: I assume that you are aware the there is a built in CheckedListBox Control?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
-
OK. Sorry. :( Keep trying though. BTW: I assume that you are aware the there is a built in CheckedListBox Control?
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
Well acually, i did not know that;) (kinda new in .NET Forms, the last forms application was Visual C++ 6, MFC) But there is a sophisticated system behind the interaction between the checkboxes in the list, if i want to convert that to a listcontrol it would take me some time, while the listbox i created now works exactly like i want, with the minor problem of scrolling. I also want to know how to properly solve this issue for future usage. Converting would be my last hope;)
-
Well acually, i did not know that;) (kinda new in .NET Forms, the last forms application was Visual C++ 6, MFC) But there is a sophisticated system behind the interaction between the checkboxes in the list, if i want to convert that to a listcontrol it would take me some time, while the listbox i created now works exactly like i want, with the minor problem of scrolling. I also want to know how to properly solve this issue for future usage. Converting would be my last hope;)
Maybe what it takes is you also executing Henry's
myUserControl.Focus();
every time your mouse wheel actions cause the checkbox states to change. Whether you also do it after a manual checkbox state change (a click) is up to you. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
Maybe what it takes is you also executing Henry's
myUserControl.Focus();
every time your mouse wheel actions cause the checkbox states to change. Whether you also do it after a manual checkbox state change (a click) is up to you. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
This also doesn't work... The checkbox mouseenter event gets triggerd, sets the focus to the usercontrol, but no scroll event is triggerd after that.
-
This also doesn't work... The checkbox mouseenter event gets triggerd, sets the focus to the usercontrol, but no scroll event is triggerd after that.
then I don't have the answer. :|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).