Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Button Cotrol: Event, when mouse leaves button with mousebutten still down

Reply
 
Old 06-24-2009   #1 (permalink)
Christian Treffler


 
 

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 SpecsSystem Spec
Old 06-29-2009   #2 (permalink)
Jack Jackson


 
 

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
I think the best you can do is to check in MouseMove if the mouse
cursor is over the button or not.
My System SpecsSystem Spec
Old 06-30-2009   #3 (permalink)
Christian Treffler


 
 

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.
Thanks,
I'll try that. Will probably not work without some delayed actions on
the screen, but better than nothing.

CU,
Christian
My System SpecsSystem Spec
Old 07-02-2009   #4 (permalink)
Christian Treffler


 
 

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.
OK, that was not so difficult:

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46