MouseOver Menu VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • S. Viswanathan

    #1

    MouseOver Menu VB.NET

    Hi All,

    I want to update the statusbar when mouse over on the each menu item. How
    to write the code for this. Is there any specific events in menu?

    Thanks and Regards
    S. Viswanathan


  • Ken Tucker [MVP]

    #2
    Re: MouseOver Menu VB.NET

    Hi,

    I dont know of any specific mouse enter and leave events. You can
    an owner drawn menu to know when the mouse is over an item and use a timer
    to clear the text in the status bar. You need four menu items for this to
    work mnufile, mnufileopen, mnufileclose, mnufilequit. All the mnuitems but
    mnufile need to be set to ownerdrawn. mnuFile is the top level menuitem.
    Hope this helps.

    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    StatusBar1.Text = ""

    End Sub

    Private Sub mnuFileClose_Me asureItem(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MeasureIt emEventArgs) Handles mnuFileClose.Me asureItem,
    mnuFileOpen.Mea sureItem, mnuFileQuit.Mea sureItem

    Dim g As Graphics = e.Graphics

    Dim mnu As MenuItem = CType(sender, MenuItem)

    Dim sz As SizeF = g.MeasureString (mnu.Text.ToStr ing, Me.Font)

    e.ItemHeight = CInt(sz.Height) + 5

    e.ItemWidth = CInt(sz.Width) + 15

    End Sub

    Private Sub mnuFileClose_Dr awItem(ByVal sender As Object, ByVal e As
    System.Windows. Forms.DrawItemE ventArgs) Handles mnuFileClose.Dr awItem,
    mnuFileOpen.Dra wItem, mnuFileQuit.Dra wItem

    Dim br As Brush = SystemBrushes.W indowText

    Dim brBack As Brush

    Dim rDraw As Rectangle

    Dim r As Rectangle = e.Bounds

    Dim mnu As MenuItem = CType(sender, MenuItem)

    Dim strText As String = mnu.Text.ToStri ng

    Dim x As Integer = r.X + 2

    Dim y As Integer = r.Y + 2

    Dim bEnabled As Boolean = mnu.Enabled

    Dim bSelected As Boolean = CBool(e.State And DrawItemState.S elected)

    Dim g As Graphics = e.Graphics

    rDraw = r

    rDraw.Inflate(-1, -1)

    g.FillRectangle (New SolidBrush(Colo r.FromArgb(128, SystemColors.Me nu)), r)

    If Not bEnabled Then

    g.DrawString(st rText, Me.Font, Brushes.Gray, 20, r.Y + 3)

    Return

    End If

    If bSelected Then

    brBack = Brushes.LightBl ue

    g.FillRectangle (Brushes.LightB lue, rDraw)

    g.DrawRectangle (Pens.Blue, rDraw)

    StatusBar1.Text = strText

    tmrClearStatusB ar.Interval = 3000 ' 3 second

    tmrClearStatusB ar.Enabled = True

    Else

    brBack = SystemBrushes.M enu

    g.FillRectangle (brBack, r)

    End If

    g.DrawString(st rText, Me.Font, Brushes.Black, 2, r.Y + 3)

    br = Nothing

    brBack = Nothing

    rDraw = Nothing

    End Sub



    Private Sub tmrClearStatusB ar_Tick(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles tmrClearStatusB ar.Tick

    StatusBar1.Text = ""

    tmrClearStatusB ar.Enabled = False

    End Sub



    Ken

    -----------------------------------

    "S. Viswanathan" <visu@ewaksoft. com> wrote in message
    news:ukTIPq0ZFH A.2884@tk2msftn gp13.phx.gbl...
    Hi All,

    I want to update the statusbar when mouse over on the each menu item. How
    to write the code for this. Is there any specific events in menu?

    Thanks and Regards
    S. Viswanathan



    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: MouseOver Menu VB.NET

      "S. Viswanathan" <visu@ewaksoft. com> schrieb:[color=blue]
      > I want to update the statusbar when mouse over on the each menu item. How
      > to write the code for this. Is there any specific events in menu?[/color]

      Add a handler to the menuitem's 'Select' event and update the statusbar
      there.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      Working...