Calculator like mouse events

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raj Chudasama

    Calculator like mouse events

    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




  • Mark Rae

    #2
    Re: Calculator like mouse events

    "Raj Chudasama" <raj@asteriasgi .com> wrote in message
    news:%239xL6a5v FHA.3548@tk2msf tngp13.phx.gbl. ..
    [color=blue]
    > 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[/color]

    With you so far...
    [color=blue]
    > however if the mouse is still over the button after clicking the button it
    > will go to the hover state.[/color]

    Doesn't do that for me - there doesn't appear to be a "hover state" of any
    kind...


    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: Calculator like mouse events

      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" <mark@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
      news:O7Aqur5vFH A.2064@TK2MSFTN GP09.phx.gbl...[color=blue]
      > "Raj Chudasama" <raj@asteriasgi .com> wrote in message
      > news:%239xL6a5v FHA.3548@tk2msf tngp13.phx.gbl. ..
      >[color=green]
      >> 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[/color]
      >
      > With you so far...
      >[color=green]
      >> however if the mouse is still over the button after clicking the button
      >> it will go to the hover state.[/color]
      >
      > Doesn't do that for me - there doesn't appear to be a "hover state" of any
      > kind...
      >[/color]


      Comment

      • Raj Chudasama

        #4
        Re: Calculator like mouse events

        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_Mou seUp(object sender, MouseEventArgs e)

        {


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

        System.Diagnost ics.Debug.Write Line("Picture box location"+
        p.Location.ToSt ring());

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

        System.Diagnost ics.Debug.Write Line("Cursor location"+
        Cursor.Position .ToString());


        Point pt = this.PointToCli ent(Cursor.Posi tion); //cursor position

        System.Diagnost ics.Debug.Write Line("this.Pare nt.PointToClien t"+
        pt.ToString());


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

        {

        picDialStar_Mou seHover(sender, e);

        return;

        }

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

        {

        :

        :

        :

        }


        Comment

        • Chris Dunaway

          #5
          Re: Calculator like mouse events

          Raj Chudasama wrote:[color=blue]
          > 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
          >[/color]

          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 bUseHoverGraphi c As Boolean

          Public Sub MouseEnter(...)
          bUseHoverGraphi c = True
          End Sub

          Public Sub MouseLeave(...)
          bUserHoverGraph ic = False
          End Sub

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

          Comment

          Working...