Incapable of listening for Mouse Events on UserControl
-
I've searched this forum and just simply can't find an answer already written out. I am creating a user control using the designer. The control only paints stuff like lines and colors within its bounds using OnPaint and OnPaintBackground. Now, I need to respond to mouse clicks, yet I cannot get the control to respond to any mouse clicks. if I do Capture = true, then it will listen to 1 single event, and then Capture is lost and i cannot click again. When I do capture, the mouse cursor turns into an hourglass anyway, which I dont want. How does one listen to events of a UserControl??? It seems this should work simply... but it does not. I am adding this control into a Table control which is in a form. There really isn't much more to it than that. I have a deadline and I'm just stumped on something that should be so ridiculously simple... yet its not. Here is the basic class I'm writing, its just a UserControl created from the visual designer. I've got breakpoints on all those mouse events and NOT ONE fires. PLEASE HELP!
public partial class HomeHeader : UserControl
{
public HomeHeader()
{
InitializeComponent();
}protected override void OnClick(EventArgs e) { base.OnClick(e); } protected override void OnMouseDoubleClick(MouseEventArgs e) { base.OnMouseDoubleClick(e); } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); }
}
-
I've searched this forum and just simply can't find an answer already written out. I am creating a user control using the designer. The control only paints stuff like lines and colors within its bounds using OnPaint and OnPaintBackground. Now, I need to respond to mouse clicks, yet I cannot get the control to respond to any mouse clicks. if I do Capture = true, then it will listen to 1 single event, and then Capture is lost and i cannot click again. When I do capture, the mouse cursor turns into an hourglass anyway, which I dont want. How does one listen to events of a UserControl??? It seems this should work simply... but it does not. I am adding this control into a Table control which is in a form. There really isn't much more to it than that. I have a deadline and I'm just stumped on something that should be so ridiculously simple... yet its not. Here is the basic class I'm writing, its just a UserControl created from the visual designer. I've got breakpoints on all those mouse events and NOT ONE fires. PLEASE HELP!
public partial class HomeHeader : UserControl
{
public HomeHeader()
{
InitializeComponent();
}protected override void OnClick(EventArgs e) { base.OnClick(e); } protected override void OnMouseDoubleClick(MouseEventArgs e) { base.OnMouseDoubleClick(e); } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); }
}
Hi, I have no trouble getting normal mouse events on a form holding two instances of this little UserControl1, which holds a ListBox, a ComboBox and a Label. The Label text gets updated for the one UserControl1 instance my mouse is hovering over, as long as I'm not over one of its internal Controls (that's why I'm having the ListBox and ComboBox).
public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void log(string s) { label1.Text=DateTime.Now.ToString("mm:ss.fff ")+s; } private void UserControl1\_MouseMove(object sender, MouseEventArgs e) { log("MouseMove"); }
or
public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void log(string s) { label1.Text=DateTime.Now.ToString("mm:ss.fff ")+s; } protected override void OnMouseMove(MouseEventArgs e) { log("MouseMove"); base.OnMouseMove(e); } }
The main difference with your code is my MouseMove handler contains real code, it does not just call base.OnMouseMove(). Instead it shows a little string in a label. IMO base.OnMouseMove() does nothing by default, an empty UserControl simply has no functionality. :)
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).
-
Hi, I have no trouble getting normal mouse events on a form holding two instances of this little UserControl1, which holds a ListBox, a ComboBox and a Label. The Label text gets updated for the one UserControl1 instance my mouse is hovering over, as long as I'm not over one of its internal Controls (that's why I'm having the ListBox and ComboBox).
public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void log(string s) { label1.Text=DateTime.Now.ToString("mm:ss.fff ")+s; } private void UserControl1\_MouseMove(object sender, MouseEventArgs e) { log("MouseMove"); }
or
public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void log(string s) { label1.Text=DateTime.Now.ToString("mm:ss.fff ")+s; } protected override void OnMouseMove(MouseEventArgs e) { log("MouseMove"); base.OnMouseMove(e); } }
The main difference with your code is my MouseMove handler contains real code, it does not just call base.OnMouseMove(). Instead it shows a little string in a label. IMO base.OnMouseMove() does nothing by default, an empty UserControl simply has no functionality. :)
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).
Sigh... Everyone ignore this thread... I am embarrassed to say that somehow i managed to not notice a large Image box in the user control designer that wasn't supposed to be there that was transparent and taking all the clicks. everything works as it should now... Sigh...
-
Sigh... Everyone ignore this thread... I am embarrassed to say that somehow i managed to not notice a large Image box in the user control designer that wasn't supposed to be there that was transparent and taking all the clicks. everything works as it should now... Sigh...
So my ListBox and ComboBox were a hint for you then. :)
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).