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

MouseOver Menu VB.NET

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

StatusBar1.Text = ""

End Sub

Private Sub mnuFileClose_MeasureItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.MeasureItemEventArgs) Handles mnuFileClose.MeasureItem,
mnuFileOpen.MeasureItem, mnuFileQuit.MeasureItem

Dim g As Graphics = e.Graphics

Dim mnu As MenuItem = CType(sender, MenuItem)

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

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

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

End Sub

Private Sub mnuFileClose_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles mnuFileClose.DrawItem,
mnuFileOpen.DrawItem, mnuFileQuit.DrawItem

Dim br As Brush = SystemBrushes.WindowText

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.ToString

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.Selected)

Dim g As Graphics = e.Graphics

rDraw = r

rDraw.Inflate(-1, -1)

g.FillRectangle(New SolidBrush(Color.FromArgb(128, SystemColors.Menu)), r)

If Not bEnabled Then

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

Return

End If

If bSelected Then

brBack = Brushes.LightBlue

g.FillRectangle(Brushes.LightBlue, rDraw)

g.DrawRectangle(Pens.Blue, rDraw)

StatusBar1.Text = strText

tmrClearStatusBar.Interval = 3000 ' 3 second

tmrClearStatusBar.Enabled = True

Else

brBack = SystemBrushes.Menu

g.FillRectangle(brBack, r)

End If

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

br = Nothing

brBack = Nothing

rDraw = Nothing

End Sub

Private Sub tmrClearStatusBar_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmrClearStatusBar.Tick

StatusBar1.Text = ""

tmrClearStatusBar.Enabled = False

End Sub

Ken

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

"S. Viswanathan" <vi**@ewaksoft.com> wrote in message
news:uk**************@tk2msftngp13.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

Nov 21 '05 #2

P: n/a
"S. Viswanathan" <vi**@ewaksoft.com> schrieb:
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?


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/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.