Label Font won't work

G

Guest

Hi,

I'm new to VB.NET and I'm trying to do something rather simple that has
turned out to be a pain in the hindside.

I'm developing a webpart. All I want to do is change the font of a label on
it. The label is created at runtime. I use the following code:

Dim lblDate as Label = New Label
lblDate.Text = Date.Today

To change the font, I understand that you have to use the System.Drawing
class. Fine. I do that, but if I do this:

lblDate.Font = New System.Drawing.Font("Verdana", 12, Drawing.FontStyle.Bold)
Then I get the error "Font is Read-Only"

If I use this instead:
lblDate.Font = New System.Drawing.Font(lblDate.Font, Drawing.FontStyle.Bold)
Then I get the error "Overload resolution failed because no accessible New
can be called with these arguments"

So please. Can somebody tell me what I'm doing wrong? I just want to make
the font bigger and set it to a different style. It's really simple stuff. I
don't get why it's such an issue in VB.NET.

Thanks in advance,
KV
 
C

Cor Ligthert

KV,

You are now using the code from a Winform, can you try this?

\\\
Label1.Text = Now.ToString
Label1.Font.Bold = True
Label1.Font.Size = FontUnit.Parse("12")
Label1.Font.Name = "Verdana"
///

I hope this helps a little bit?

Cor
 
G

Guest

That's exactly what I needed. Thanks a lot. I originally tried it that way,
but didn't know about the .parse bit, and a search on the internet lead to
the other solutions.

Thanks Again,
KV
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top