473,503 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Label Font won't work

KV
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
Nov 21 '05 #1
2 5823
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
"KV" <KV@discussions.microsoft.com>
...
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

Nov 21 '05 #2
KV
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

"Cor Ligthert" wrote:
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
"KV" <KV@discussions.microsoft.com>
...
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


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12302
by: Stuart Norris | last post by:
Dear Readers, I am attempting to draw box around some text using unicode on multiline label. The label is forty characters wide and 12 lines deep. I have been trying to draw a box around text...
1
1894
by: Venki | last post by:
I have a textbox to enter an email address followed by a telephone textbox. The email has a regularexpressionvalidator and a requiredfieldvalidator. The ReqField works fine, but if I put in an...
2
1739
by: Peter Rilling | last post by:
Below is some code that I do not know why it does not work. Okay, as you can see it is simple HTML with two ASP:Label controls. Each label has some code that basically gets a string that will be...
3
14983
by: Michael | last post by:
Hi, I'm trying to print barcodes to the Dymo LabelWriter printer. Put everytime I send a job to the label printer it just outputs an empty label. If I change the default printer back to the...
7
19510
by: Joe | last post by:
I have a label control that will be filled with text at runtime. The length of the text will vary, but the label must stay the same size. Is there a way to set the font size of the text such that...
2
7949
by: André Hänsel | last post by:
Hi again, I have a radio button: <p> <input id="v_yes" type="radio" name="v" value="yes" /> <label for="v_yes">Ja</label> <input id="v_no" type="radio" name="v" value="no" /> <label...
0
1508
by: Kevin McKinley | last post by:
Below i've put the code for a program that i wrote. I need help on lines 384-403. If you run this program you will notice on the first tab when have it produce an answer the $ is surrounded with...
0
1488
by: Guilherme Polo | last post by:
On Wed, Sep 3, 2008 at 8:57 PM, Kevin McKinley <kem1723@yahoo.comwrote: Come on.. "help on lines 384-403", that is not a good way to look for help. You are supposed to post some minimal code that...
6
8797
by: Miro | last post by:
Is there a way to / or a mathematical formula to see if a font size is 'too big' for a label. I have a label that is docked to 'fill' a form, and I want to resize that font based on the width...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.