Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

yeah , you need to make the menu's " OwnerDraw " , then use an imagelist , then on the " Draw " and " Measure " subs of the menuitems , just use the graphics to create the menu / with icons.

only a few lines of code and you are on the way :)

  • Leaders
Posted

here's a simple example i made just for you :) , i've included a demo source code zip to make it easier to go through .

   Private WithEvents mnuItems As MenuItem

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       AddHandler MenuItem2.MeasureItem, AddressOf mnuItems_MeasureItem
       AddHandler MenuItem3.MeasureItem, AddressOf mnuItems_MeasureItem
       AddHandler MenuItem2.DrawItem, AddressOf mnuItems_DrawItem
       AddHandler MenuItem3.DrawItem, AddressOf mnuItems_DrawItem
   End Sub

   Private Sub mnuItems_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles mnuItems.MeasureItem
       With e
           .ItemHeight = 20
           .ItemWidth = 100
       End With
   End Sub


   Private Sub mnuItems_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles mnuItems.DrawItem
       If Not e.State = 256 Then
           With e.Graphics
               .FillRectangle(New SolidBrush(Color.Blue), e.Bounds.X + 20, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
               .DrawRectangle(New Pen(Color.Blue), e.Bounds.X + 20, e.Bounds.Y, e.Bounds.Width - 21, e.Bounds.Height - 1)
               .DrawString(sender.text, New Font("Tahoma", 10, FontStyle.Regular), New SolidBrush(Color.White), 22, e.Bounds.Y + 3)
               .DrawImage(ImageList1.Images.Item(0), e.Bounds.X + 1, e.Bounds.Y + 3)
           End With
       Else
           With e.Graphics
               .FillRectangle(New SolidBrush(Color.LightBlue), e.Bounds.X + 20, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
               .DrawRectangle(New Pen(Color.Gray), e.Bounds.X + 20, e.Bounds.Y, e.Bounds.Width - 21, e.Bounds.Height - 1)
               .DrawString(sender.text, New Font("Tahoma", 10, FontStyle.Regular), New SolidBrush(Color.White), 22, e.Bounds.Y + 3)
               .DrawImage(ImageList1.Images.Item(1), e.Bounds.X + 1, e.Bounds.Y + 3)
           End With
       End If
   End Sub

windowsapplication21.zip

  • *Experts*
Posted

Mine comes with full source, meaning you can add the source files to your project and use it, and it will compile directly into your project with no extra dependency.

 

Also, attempting to keep your apps as one exe file is pretty pointless anyway. When you deploy your applications, the System.dll and System.Windows.Forms.dll and whatnot need to be deployed as well (for computers without the .NET framework), so you'll always have dependency.

Posted

some more questions:

1. How do i add your code to the project?

2. Does it work for a contextmenu when it is link to a tray icon? i get a small strip thats all???

 

btw: I'm not going to make a setup, they can dowwload the framework form microsoft.com, so they only need one exe.

 

greets and thanx agen

  • *Experts*
Posted

As long as the item you're adding menus to is MenuItem, it doesn't matter how it's used.

 

To add code to the project, simply add my source files to your project with the Solution Explorer. However, it would be easier if you simply made it into a separate DLL. Since it is a .NET DLL it doesn't require any registration and only needs to sit in the directory with the EXE.

  • *Experts*
Posted
Well, I'm not exactly sure. You may need to modify my code a little bit and change all the instances of "MainMenu" to "ContextMenu". The MenuItems they use are the same, but I may have hardcoded the use of MainMenus into it, so a bit of tweaking should do it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...