J. Ross Hughson
asked on
In vb.net, how do I set a font size when creating a text box programmatically?
I am programming in vb.net with Visual Studio 2015 Community. I am using the code below to programmatically create a text box. My question is - How can I set the text font size when the box is created. I looked around and found the code between the asterisks below, but I'm getting a compile error saying that Font is ambiguous. This is occurring for the first Font in the using f as Font statement and also the Font after the New in the following line. I'm very new to programming in vb and would appreciate any help you could give. Thanks.
tbnum.Location = New System.Drawing.Point(30, tvposition)
tbnum.Size = New Size(45, 20)
'********************
Using f As Font = tbnum.Font
tbnum.Font = New Font(f.FontFamily, f.Size + 2, f.Style)
End Using
'********************
tbnum.Text = panposition.ToString
tbnum.Name = "tbnum" + panposition.ToString
tbnum.AllowDrop = True
tbnum.TabStop = False
tbnum.TextAlign = HorizontalAlignment.Right
tbnum.BackColor = ColorTranslator.FromHtml(myYellow)
tbnum.ReadOnly = True
tbnum.Enabled = False
Controls.Add(tbnum)
ASKER
Thanks Najam. I had to get rid of the f.style parameter but once I did that, it worked perfectly. What about bolding the text? How would I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window