jorge Posted July 27, 2003 Posted July 27, 2003 Hey is it pasible to add icons to menus(context) without using an external dll? i'd like to keep my apps as one exe file. thanx in advance Quote Jorge - http://www.blackdot.be/?page=apache.htm
Leaders dynamic_sysop Posted July 27, 2003 Leaders Posted July 27, 2003 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 :) Quote
jorge Posted July 27, 2003 Author Posted July 27, 2003 any example or is it so easy i can find it by playing with it? well i'll try by playing for now ;) Quote Jorge - http://www.blackdot.be/?page=apache.htm
Leaders dynamic_sysop Posted July 27, 2003 Leaders Posted July 27, 2003 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 Quote
jorge Posted July 28, 2003 Author Posted July 28, 2003 (edited) Ok, I'l try both, IF i run into problems i'll let you know. btw:VF, the one you gave compiles into a dll, and i want only one exe file, But none work when using as a context menu for a trayicon :s. thanx agen Edited July 28, 2003 by jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
*Experts* Volte Posted July 28, 2003 *Experts* Posted July 28, 2003 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. Quote
jorge Posted July 28, 2003 Author Posted July 28, 2003 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 Quote Jorge - http://www.blackdot.be/?page=apache.htm
*Experts* Volte Posted July 28, 2003 *Experts* Posted July 28, 2003 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. Quote
jorge Posted July 28, 2003 Author Posted July 28, 2003 Cool, got it to work for normal menus in a test project :D but won't work in as a menu called from a trayicon, you know whats wrong? give's a blanck strip :( ask if you need a screenshot greets Jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
*Experts* Volte Posted July 28, 2003 *Experts* Posted July 28, 2003 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. Quote
jorge Posted July 28, 2003 Author Posted July 28, 2003 :eek: screwd up the code, i'll try agen, But the strage thing is, it work in a context menu, if its on a form???? Quote Jorge - http://www.blackdot.be/?page=apache.htm
*Gurus* divil Posted July 28, 2003 *Gurus* Posted July 28, 2003 You cannot ownerdraw a context menu displayed on a system tray icon. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
jorge Posted July 29, 2003 Author Posted July 29, 2003 Ok, Tobad, but i atleast now it's not me that is doing somting wrong. Strange do i've seen it be done befor, aldo i don't thing the code was vb.net :/ Quote Jorge - http://www.blackdot.be/?page=apache.htm
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.