Results 1 to 2 of 2

Thread: Icons in the menus

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Durham, NC
    Posts
    28

    Icons in the menus

    I recently got Visual Basic.net and so far I'm liking it.

    But how do I get icons beside the menu items on the forms. I read somewhere that it has something to do with the ownerdraw property but I have no idea how to do this.

  2. #2
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    This works with ownerdraw set to true. You'll have to change the colors to what you want, but this should be a good start.

    private MyMenuText as string = "My Menu"

    Private Sub MenuItem2_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MenuItem2.DrawItem

    e.DrawBackground()
    Dim G As Graphics = e.Graphics
    Dim X as integer = 35 'Offset text past icon
    Dim Y as integer = 9 'Center text in menuitem

    G.FillRectangle(New SolidBrush(Color.White), e.Bounds)
    G.DrawRectangle(System.Drawing.Pens.Green, e.Bounds)

    G.DrawIcon(New Icon("App.ico"), 0, 0)
    G.DrawString(MyMenuText, Me.Font, New SolidBrush(Color.Red), e.Bounds.X + X, e.Bounds.Y + Y)
    End Sub


    Private Sub MenuItem2_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles MenuItem2.MeasureItem

    Dim S As SizeF = e.Graphics.MeasureString(MyMenuText, Me.Font)
    Dim X as integer = 45 'Extra width for menu.
    Dim Y as integer = 20 'Extra height for menu.

    e.ItemHeight = CType(S.Height + Y, Integer)
    e.ItemWidth = CType(S.Width + X, Integer)

    End Sub
    That which does not kill us, only makes us stronger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width