Calculator like mouse events

  • Thread starter Thread starter Raj Chudasama
  • Start date Start date
R

Raj Chudasama

I have a controls similiar to the windows calculator. (Please press some
buttons on your calculator to see what i am talking about)

So when u hover over a button it will change the state (it changes to
different image)
if u click it will show pressed image etc

now the problem:

the calculator does the following

when a button is clicked via mouse a pressed image is shown and when the
mouse is up it will show up state however if the mouse is still over the
button after clicking the button it will go to the hover state.

i am currently unable to do this. My control will show hover state, if you
press it will show pressed state and then the up state. however even if you
have your mouse still over the button after clicking the button it will not
show the hover state.



I am sure i have to "consume" an event or something but i don t know how and
which.

please help
 
the calculator does the following

when a button is clicked via mouse a pressed image is shown and when the
mouse is up it will show up state

With you so far...
however if the mouse is still over the button after clicking the button it
will go to the hover state.

Doesn't do that for me - there doesn't appear to be a "hover state" of any
kind...
 
Well i guess it will depend on what win version you are using, i am on XP
and it does the hover states. However mine are custom buttons that are
dropped on a picturebox and events tied to them.

Nonetheless, i got it figured out

what i did is the following:

i added code to the mouseup event... so when mouse is up it will check to
see if the mouse is till on the button it clicked on. if so then i just
call the mouse hover code on that button

private void picDialStar_MouseUp(object sender, MouseEventArgs e)

{


PictureBox p = (PictureBox)sender; //get current button that was clicked

System.Diagnostics.Debug.WriteLine("Picture box location"+
p.Location.ToString());

Rectangle r = new Rectangle(p.Location,p.Size); //picturbox rectangle

System.Diagnostics.Debug.WriteLine("Cursor location"+
Cursor.Position.ToString());


Point pt = this.PointToClient(Cursor.Position); //cursor position

System.Diagnostics.Debug.WriteLine("this.Parent.PointToClient"+
pt.ToString());


if(r.Contains(pt)) //if the rectangle contains the cursor then we should
show the hover state

{

picDialStar_MouseHover(sender,e);

return;

}

else //mouse is not over the image that was clicked so just show the up
state.

{

:

:

:

}
 
Raj said:
Well i guess it will depend on what win version you are using, i am on XP
and it does the hover states. However mine are custom buttons that are
dropped on a picturebox and events tied to them.

Nonetheless, i got it figured out

All you need to do is handle MouseEnter and MouseLeave for the buttons.
In the MouseEnter, set a boolean or something to indicate that the
hover graphic should be used and in the mouseLeave, it indicates the
normal unclicked graphic.

Then, in the MouseUp, you display the correct one.

Private bUseHoverGraphic As Boolean

Public Sub MouseEnter(...)
bUseHoverGraphic = True
End Sub

Public Sub MouseLeave(...)
bUserHoverGraphic = False
End Sub

Public Sub MouseUp(...)
If bUserHoverGraphic Then
'Paint button with hover graphic
Else
'Paint button with normal graphic
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top