PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to make certain text in a context menu be bold-VBForums
Results 1 to 3 of 3

Thread: How to make certain text in a context menu be bold

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,421

    How to make certain text in a context menu be bold

    Hi everyone, I came across this code and it's not mine, but I thought maybe someone would like to see it. For many months I've looked for how to make just one line of text in a context menu be bold and I never found a way until now.

    I don't use the Designer to make context menus so I hope you will not be upset with me for that
    Here is the code that calls a function to make the item font be bold...
    Code:
            myString = "d"
            myString = myString.PadLeft(CInt(31))
    
            DeleteWallpaper = New ToolStripMenuItem("&Delete Wallpaper" & myString)
            ret = rk.GetValue("ShowDeleteWallpaperIcon") 'Get value from registry
    
            With DeleteWallpaper
                If CBool(ret) Then
                    .Image = My.Resources.trash
                    With ShowMenuImages
                        .ShowDeleteWallpaperIcon.Checked = True 'If true, Menu Icons are visible
                    End With
                End If
    
                .ImageScaling = ToolStripItemImageScaling.SizeToFit
                .ForeColor = Color.Beige
                .Font = CreateFont("Segoe UI", CInt(9.5), True, False, False) <-- SET THE FONT
            End With
    And here's the function that does the Font...
    Code:
      Public Function CreateFont(ByVal fontName As String,
                                   ByVal fontSize As Integer,
                                   ByVal isBold As Boolean,
                                   ByVal isItalic As Boolean,
                                   ByVal isStrikeout As Boolean) As Font
    
            Dim styles As FontStyle = FontStyle.Regular
            If (isBold) Then
                styles = styles Or FontStyle.Bold
            End If
    
            If (isItalic) Then
                styles = styles Or FontStyle.Italic
            End If
    
            If (isStrikeout) Then
                styles = styles Or FontStyle.Strikeout
            End If
    
            Dim newFont As New Font(fontName, fontSize, styles)
            Return newFont
    
        End Function
    So if you too ever wondered if you can make a single string in a context menu bold, this will do the job
    Thanks for checking this out. Hope someone finds it useful...

    Edit: Here's a screen shot of my context menu. The "Delete" line uses Color.Azure
    Name:  Clipboard-1.png
Views: 47
Size:  21.9 KB
    Last edited by jumper77; Feb 21st, 2020 at 02:33 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,150

    Re: How to make certain text in a context menu be bold

    Quote Originally Posted by jumper77 View Post
    So if you too ever wondered if you can make a single string in a context menu bold, this will do the job
    Or you could just do it in the designer and set the Font.Bold property to True. As for doing it in code, I just successfully tried the following on a menu that I created in the designer:
    vb.net Code:
    1. myToolStripMenuItem.Font = New Font(myToolStripMenuItem.Font, myToolStripMenuItem.Font.Style Or FontStyle.Bold)
    I would assume that the same thing would work with one created in code.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2016
    Location
    Tennessee
    Posts
    2,421

    Re: How to make certain text in a context menu be bold

    A much better solution my friend. I had to make some changes, but I was able to get it to work. Here's is the new code for the MenuItem...
    Code:
      DeleteWallpaper = New ToolStripMenuItem("&Delete Wallpaper" & myString)
            ret = rk.GetValue("ShowDeleteWallpaperIcon")
            With DeleteWallpaper
                If CBool(ret) Then
                    .Image = My.Resources.trash
                End If
                .ImageScaling = ToolStripItemImageScaling.SizeToFit
                .ForeColor = Color.Azure
                .Font = New Font(.Font, .Font.Style Or FontStyle.Bold)
            End With
    I'm all for anything that takes less code, so I like your solution for sure. I appreciate your input and I'll be using your code now instead of the one I posted

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width