-
Feb 21st, 2020, 02:19 PM
#1
Thread Starter
PowerPoster
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
Last edited by jumper77; Feb 21st, 2020 at 02:33 PM.
-
Feb 22nd, 2020, 04:33 AM
#2
Re: How to make certain text in a context menu be bold
Originally Posted by jumper77
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:
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.
-
Feb 22nd, 2020, 05:31 AM
#3
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|