By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,491 Members | 1,168 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,491 IT Pros & Developers. It's quick & easy.

Calculator like mouse events

P: n/a
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


Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Raj Chudasama" <ra*@asteriasgi.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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...
Nov 17 '05 #2

P: n/a
Hi,

The same here, it does not has a hover state

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:O7**************@TK2MSFTNGP09.phx.gbl...
"Raj Chudasama" <ra*@asteriasgi.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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...

Nov 17 '05 #3

P: n/a
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.Po intToClient"+
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.

{

:

:

:

}
Nov 17 '05 #4

P: n/a
Raj Chudasama wrote:
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

Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.