![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Button Cotrol: Event, when mouse leaves button with mousebutten still down Hi, I wrote some code to add images to button controls (.Net 2.0, Visual Studio 2005, C#). There are 4 images for 4 states: normal, mousebutton down, mousenter, disabled. So far everything works with only a small problem: If I click on the button and drag the mouse pointer from the control with mouse button still down, the MouseLeave event is not triggered. The button outline goes back to the normal state, but the image changes back to normal only after I release the mousebutton. I can't fins an event which catches 'Leave control with mouse button still down'. Here's a piece of my code: public static void AddHandler(Button btn) { \\ Assign the methods to the events btn.MouseDown += new System.Windows.Forms.MouseEventHandler(BtnDown); btn.MouseUp += new System.Windows.Forms.MouseEventHandler(BtnUp); btn.MouseEnter += new System.EventHandler(BtnEnter); btn.MouseLeave += new System.EventHandler(BtnLeave); } public static void BtnDown(object sender, EventArgs e) { Button btn = (Button)sender; btn.ImageIndex = 1; // The button ImageList property // contains an imagelist with the 4 images } public static void BtnUp(object sender, EventArgs e) { Button btn = (Button)sender; btn.ImageIndex = 0; } public static void BtnEnter(object sender, EventArgs e) { Button btn = (Button)sender; btn.ImageIndex = 2; } public static void BtnLeave(object sender, EventArgs e) { Button btn = (Button)sender; btn.ImageIndex = 0; } CU, Christian |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Button Cotrol: Event, when mouse leaves button with mousebutten still down On Wed, 24 Jun 2009 19:52:41 +0200, Christian Treffler <CTreffler.NG.Dev0@xxxxxx> wrote: Quote: >Hi, > >I wrote some code to add images to button controls (.Net 2.0, Visual >Studio 2005, C#). There are 4 images for 4 states: normal, mousebutton >down, mousenter, disabled. > >So far everything works with only a small problem: If I click on the >button and drag the mouse pointer from the control with mouse button >still down, the MouseLeave event is not triggered. The button outline >goes back to the normal state, but the image changes back to normal only >after I release the mousebutton. >I can't fins an event which catches 'Leave control with mouse button >still down'. > >Here's a piece of my code: > >public static void AddHandler(Button btn) > { \\ Assign the methods to the events > btn.MouseDown += new System.Windows.Forms.MouseEventHandler(BtnDown); > btn.MouseUp += new System.Windows.Forms.MouseEventHandler(BtnUp); > btn.MouseEnter += new System.EventHandler(BtnEnter); > btn.MouseLeave += new System.EventHandler(BtnLeave); > } > >public static void BtnDown(object sender, EventArgs e) > { > Button btn = (Button)sender; > btn.ImageIndex = 1; // The button ImageList property > // contains an imagelist with the 4 images > } > >public static void BtnUp(object sender, EventArgs e) > { > Button btn = (Button)sender; > btn.ImageIndex = 0; > } > >public static void BtnEnter(object sender, EventArgs e) > { > Button btn = (Button)sender; > btn.ImageIndex = 2; > } > >public static void BtnLeave(object sender, EventArgs e) > { > Button btn = (Button)sender; > btn.ImageIndex = 0; > } > > >CU, >Christian cursor is over the button or not. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Button Cotrol: Event, when mouse leaves button with mousebutten still down Jack Jackson schrieb: Quote: > I think the best you can do is to check in MouseMove if the mouse > cursor is over the button or not. I'll try that. Will probably not work without some delayed actions on the screen, but better than nothing. CU, Christian |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Button Cotrol: Event, when mouse leaves button with mousebutten still down Christian Treffler schrieb: Quote: > Jack Jackson schrieb: > Quote: >> I think the best you can do is to check in MouseMove if the mouse >> cursor is over the button or not. > Thanks, > I'll try that. Will probably not work without some delayed actions on > the screen, but better than nothing. public static void BtnMove(object sender, MouseEventArgs e) // Handler to check, if button is left with mouse down { Button btn = (Button)sender; if (e.X < 0 || // Mouse Pointer not within button rectangle? e.Y < 0 || e.X > btn.Size.Width || e.Y > btn.Size.Height) { int[] i = (int[])btn.Tag; // get index list btn.ImageIndex = i[0]; // #0 is for normal state } else if (e.Button == MouseButtons.Left) // else check, if button is still down { int[] i = (int[])btn.Tag; // get index list btn.ImageIndex = i[1]; // #1 is for button down } } Thanks for your tip. CU, Christian |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Scan Button Event | Vista print fax & scan | |||
| No right mouse button | Vista account administration | |||
| Vista SP2: Stop button disabled when Send/Recv button pressed | Vista mail | |||
| Mouse Button | Tutorials | |||
| 3 button mouse | Vista General | |||