1

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)
1
  • You NEVER should name your type like one of the .Net framework class library members, because you will get messing with an ambiguous name like in this case "Font". Just rename your type. Commented Nov 3, 2015 at 1:13

1 Answer 1

1

The error you are getting means that you have two classes named Font. Do you use any libraries that contain a class called Font?

In all cases, to disambiguate, use the full class name, i.e., System.Drawing.Font like this:

Using f As System.Drawing.Font = tbnum.Font
    tbnum.Font = New System.Drawing.Font(f.FontFamily, f.Size + 2, f.Style)
End Using
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.