|
-
Mar 7th, 2017, 11:40 AM
#1
-
Mar 7th, 2017, 11:54 AM
#2
Re: Treeview Node Font
I *think* you should be able to do it by accessing the Font property of that specific TreeViewItem... I think...
You should be able to create a new font instance using the current font as a template and flipping on the underline flag, and then assign that back to the Font property for that specific TreeViewItem.
It should work.
-tg
-
Mar 7th, 2017, 12:11 PM
#3
Re: Treeview Node Font
Each TreeNode has a NodeFont property.
Getting an underlined font is weird, because you can't really change a Font on the fly. Supposing you already had the node you wanted, it'd look something like:
Code:
Dim oldFont = node.NodeFont
Dim newFont As new Font(oldFont, FontStyle.Underline)
node.NodeFont = newFont
There's one quirk you might run into: if a TreeNode's Font property is Nothing, it uses the TreeView's Font, so you might have better results relying on that. My code above might toss a NullReferenceException.
-
Mar 7th, 2017, 12:55 PM
#4
Re: Treeview Node Font
Thanks Sitten
here is what I did:
vb.net Code:
Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline)
Dim f2 As New Font(f, FontStyle.Bold)
tvCatalog.Nodes(0).Nodes(intNodeId).Nodes(intNode2).Nodes(intProjectNode).Nodes(intProjParmNode).Nodes(intlocalNode).Nodes.Add("SetEV", "Set From Enviorment Variable: " & drProjParams.GetString(7), 1)
tvCatalog.Nodes(0).Nodes(intNodeId).Nodes(intNode2).Nodes(intProjectNode).Nodes(intProjParmNode).Nodes(intlocalNode).Nodes(intlocalNode).BackColor = Color.PaleTurquoise
tvCatalog.Nodes(0).Nodes(intNodeId).Nodes(intNode2).Nodes(intProjectNode).Nodes(intProjParmNode).Nodes(intlocalNode).Nodes(intlocalNode).NodeFont = f2
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 7th, 2017, 01:00 PM
#5
Re: Treeview Node Font
Why this
Code:
Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline)
Dim f2 As New Font(f, FontStyle.Bold)
when this works:
Code:
Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline & FontStyle.Bold)
(to be fair, I can't remember if the flags should be & together or + together... one or both should work).
-tg
-
Mar 7th, 2017, 01:10 PM
#6
Re: Treeview Node Font
I need to correct... when I added the second font style I lost the underline. When I tried to do the FontStyle.Underline & FontStyle.Bold I get error:
Severity Code Description Project File Line Suppression State
Error BC30518 Overload resolution failed because no accessible 'New' can be called with these arguments:
'Public Overloads Sub New(family As FontFamily, emSize As Single, style As FontStyle)': Value of type 'String' cannot be converted to 'FontFamily'.
'Public Overloads Sub New(family As FontFamily, emSize As Single, style As FontStyle)': Option Strict On disallows implicit conversions from 'Integer' to 'FontStyle'.
'Public Overloads Sub New(family As FontFamily, emSize As Single, unit As GraphicsUnit)': Value of type 'String' cannot be converted to 'FontFamily'.
'Public Overloads Sub New(family As FontFamily, emSize As Single, unit As GraphicsUnit)': Option Strict On disallows implicit conversions from 'Integer' to 'GraphicsUnit'.
'Public Overloads Sub New(familyName As String, emSize As Single, style As FontStyle)': Option Strict On disallows implicit conversions from 'Integer' to 'FontStyle'.
'Public Overloads Sub New(familyName As String, emSize As Single, unit As GraphicsUnit)': Option Strict On disallows implicit conversions from 'Integer' to 'GraphicsUnit'. MySSISDBBrowser C:\Users\gmazz\Documents\Visual Studio 2015\Projects\MySSISDBBrowser\MySSISDBBrowser\frmMain.vb 11 Active
same with +
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 7th, 2017, 02:00 PM
#7
Re: Treeview Node Font
"&" is for String concatenation. "+" is for String concatenation and adding numbers.
When you want to use bitwise operations, you have to use And or Or. Speaking in terms of English, "And" sounds right. Speaking in terms of how programming works, "Or" is right:
Code:
New Font(f, FontStyle.Bold Or FontStyle.Underline)
-
Mar 7th, 2017, 02:02 PM
#8
Re: Treeview Node Font
Didn't see this:
 Originally Posted by techgnome
Why this
Code:
Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline)
Dim f2 As New Font(f, FontStyle.Bold)
when this works:
Code:
Dim f As New Font("Microsoft Sans Serif", 8, FontStyle.Underline & FontStyle.Bold)
(to be fair, I can't remember if the flags should be & together or + together... one or both should work).
-tg
Smart-aleck answer: because the '&' operator is only used for bitwise operations in C#. 
Other smart-aleck answer: because the first block of code doesn't try to make the text bold AND underlined, that constructor for Font() should read as follows: "Use the same font size and family as this font, but let me define a new style".
Also: you can't misspell a font name when you use the original font as the "prototype".
Also: MS Sans Serif was the default font for Win 3.1, it's time to move to Segoe UI or at least Tahoma.
It's generally more common that you have a not-bold font you want to make bold, and it's a pain in the butt to grab all the other stuff you need to make the font. So this is a convenience overload. Not every project uses the same font throughout, and in situations like a RichTextBox you can have a multitude of Font objects in play.
Last edited by Sitten Spynne; Mar 7th, 2017 at 02:05 PM.
-
Mar 7th, 2017, 02:08 PM
#9
Re: Treeview Node Font
Thanks got it, I added that to get the look I wanted.
Sometimes the Programmer
Sometimes the DBA
Mazz1
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
|