All source code in .Net Ask a .Net Pro Discussion Forum Categories All jobs in .Net
NET,first,code,side,Planet,Source,Codes,secti
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 666,891. lines
 Jobs: 818. postings

 How to support the site

 
Sponsored by:
Quick Search for:  in language:    
You are in:
 
Login





Latest postings for .Net.
SQL Backup/Restore using SMO
By Visual Soft Computers on 2/6


Click here to see a screenshot of this code!flexi grid
By maytel.mynt on 1/12

(Screen Shot)

Using Excel in VB2010 (VB10)
By Alberto Torres on 2/5


Click here to see a screenshot of this code!SermonNotes
By arifliminto86 on 2/5

(Screen Shot)

Click here to see a screenshot of this code!A.net Programm to add new database
By Rohit Kanugo on 2/5

(Screen Shot)

Access_Database _Add
By Rohit Kanugo on 2/4


Add new DataBase Through Coding for a IT Company
By Rohit Kanugo on 2/4


Click here to put this ticker on your site!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Icons in VB .NET Menus!!!!!

Print
Email
 
VB icon
Submitted on: 3/29/2002 10:27:04 AM
By: The New iSoftware Company!  
Level: Advanced
User Rating: By 7 Users
Compatibility:VB.NET

Users have accessed this code 75721 times.
 
 
     This is the first code on the .NET side of Planet Source Code's VB section to do this. I am proud to post a sample of Dr. GUI's sample code. I made a lot of changes to the original code like adding comments to it. It still needs some work. Well commented. Read the label of the screen shot, please. Don't forget to comment and vote! PS. It can be used in place of any menuitem. (Could not be uploaded. Here is the class.) ***New version bug (need help) email me if you wish to help! This is NOT C# code!

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: Icons in VB .NET Menus!!!!!
    // Description:This is the first code on
    //     the .NET side of Planet Source Code's VB
    //     section to do this. I am proud to post a
    //     sample of Dr. GUI's sample code. I made 
    //     a lot of changes to the original code li
    //     ke adding comments to it. It still needs
    //     some work. Well commented. Read the labe
    //     l of the screen shot, please. Don't forg
    //     et to comment and vote! PS. It can be us
    //     ed in place of any menuitem. (Could not 
    //     be uploaded. Here is the class.) ***New 
    //     version bug (need help) email me if you 
    //     wish to help! This is NOT C# code!
    // By: The New iSoftware Company!
    //
    // Side Effects:Does not highlight. Sort
    //     a basic.
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=179&lngWId=10    //for details.    //**************************************
    //     
    
    Public Class clsMenuIcons
    'Original Code by Dr. GUI and the People at Microsoft.
    'Modifications By The New iSoftware.
    'Please give credit.
    #Region " Visual Basic .NET Icons on MenuItems Class File "
    Inherits MenuItem
    Public Icon As Icon
    Public Font As Font
    Sub New(ByVal Text As String, ByVal EventHandler As EventHandler, ByVal Shortcut As Shortcut, ByVal Icon As Icon)
    MyBase.New(Text, EventHandler, Shortcut) 'Creates Base Menu Meth. and Prop.
    Me.OwnerDraw = True 'Required. Allows the OnMeasureItem and OnDrawItem overrides.
    Me.Icon = Icon 'Sets the icon.
    Me.Font = SystemInformation.MenuFont 'Sets font to normal, can be overridden.
    End Sub
    Protected Overrides Sub OnMeasureItem(ByVal E As MeasureItemEventArgs)
    MyBase.OnMeasureItem(E) 'Do this first. Fires code for this.
    Dim sfStringFormat As New StringFormat()
    sfStringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show 'The _ for &.
    sfStringFormat.SetTabStops(50, New Single() {0}) 'Declares tab.
    If Icon.Height > Font.Height Then 'Sets height.
    E.ItemHeight = Me.Icon.Height + 2 'Icon as base.
    Else
    E.ItemHeight = Me.Font.Height + 2 'Font as base. 
    End If
    E.ItemWidth = CInt(E.Graphics.MeasureString(AppendShortcut(), Me.Font, 1000, sfStringFormat).Width) + Icon.Width + 5 ' Width Set
    sfStringFormat.Dispose() 'Clean Up!
    End Sub
    Protected Overrides Sub OnDrawItem(ByVal E As DrawItemEventArgs)
    MyBase.OnDrawItem(E) 'Do this first. Fires code for this.
    Dim brBrush As Brush
    Dim sfStringFormat As New StringFormat()
    E.Graphics.FillRectangle(SystemBrushes.Menu, E.Bounds) 'Draws BG.
    If Not (Icon Is Nothing) Then
    E.Graphics.DrawIcon(Icon, E.Bounds.Left + 1, E.Bounds.Top + 1) 'Draws Icon. any size works at org size.
    End If
    sfStringFormat.HotkeyPrefix = Drawing.Text.HotkeyPrefix.Show 'The _ for &.
    sfStringFormat.SetTabStops(50, New Single() {0}) 'Declares tab.
    brBrush = New SolidBrush(SystemColors.MenuText) 'Sets the brush color.
    E.Graphics.DrawString(AppendShortcut(), Me.Font, brBrush, E.Bounds.Left + Icon.Width + 10, E.Bounds.Top, sfStringFormat) 'Draws text.
    brBrush.Dispose() 'Clean Up!
    sfStringFormat.Dispose()
    End Sub
    Private Function AppendShortcut() As String 'Basicaly determines to draw the HeldButtton+AnyKey thing. 
    Dim sTemp As String
    sTemp = Me.Text
    If Me.ShowShortcut And Me.Shortcut <> Shortcut.None Then
    Dim kKeys As Keys = CType(Shortcut, Keys)
    sTemp = sTemp & Convert.ToChar(9) & System.ComponentModel.TypeDescriptor.GetConverter(GetType(Keys)).ConvertToString(kKeys)
    End If
    Return sTemp
    End Function
    #End Region
    End Class


Other 7 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/30/2002 9:20:15 AMThe New iSoftware Company!

If you people are needing help using this read or use this (* = new line):*
Dim eh as EventHandler *
Dim WithEvents mnuMenuName as New clsMenuIcons("Text Caption", eh, Shortcut.SomeSC, SomeIcon)*
'The Form load *
mnuParentMenuItem.MenuItems.Add(mnuMenuName)*
'Events
Private Sub mnuMenuName_Click(ByVal sender as Object, ByVal e as EventHandler) Handles mnuMenuName.Click *
'Code Here*
End Sub *
(If this comment was disrespectful, please report it.)

 
3/30/2002 10:46:00 AMroswellevent

Great Code!!!!!
That what i need!
thx for sharing your code!
(If this comment was disrespectful, please report it.)

 
3/30/2002 8:17:57 PMThe New iSoftware Company!

Please vote.
(If this comment was disrespectful, please report it.)

 
4/12/2002 3:50:00 AMIanW

I can't believe Microsoft haven't made icon menus a standard feature. I'll keep this for when I make the move to .net.
(If this comment was disrespectful, please report it.)

 
5/24/2002 4:03:27 PMMattias

Its a good thing you made this!!
But it would be even greater to make the Office XP menu thing i mean THATS what i call menu!
But its still great you made this!!!
(Hehe i havent tried it yet but i hope it works)
I will give you 5/5 for this one!
(If this comment was disrespectful, please report it.)

 
6/5/2002 7:11:52 PMKetan

This didn't work for me .. where do you actually get the icon from? I know I have to pass it to the class but in the example it doesn't say how to get the icon from the path .. please help.

Thanks
Ketan
(If this comment was disrespectful, please report it.)

 
6/10/2002 5:34:40 PMNew iSoft

Apply a icon class to the Icon item.
(If this comment was disrespectful, please report it.)

 
6/19/2002 11:18:27 AMAmeen Tayyebi

It would be better if you provide documentation on how to use this and how to do it, how to place icons for several menu items, etc.
(If this comment was disrespectful, please report it.)

 
6/20/2002 12:54:19 PMFlavio

Cool!
(If this comment was disrespectful, please report it.)

 
1/5/2003 4:15:40 AM

What's better, VB 6 or .NET? i started 6 learning Edition, and now i can't find profesional edition anywhere,i have .NET but i don't like it as much, VB ^ was much, much easier that .NET :-(
(If this comment was disrespectful, please report it.)

 
5/6/2003 3:23:13 AMchenfs

Do you have any example on how to assign the icon class to your new MenuItem Class ?? Thanks
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Games | Feedback | Customize | .Net Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2010 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.