473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to make bold part of a label?

How to make bold part of the text in a Windows.Forms.Label? Thank you.

Aug 5 '07 #1
8 30912
Alexey,

You can create a new Font instance which has the FontStyle.Bold value
set and then set the Font property on the label class to that Font instance.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
How to make bold part of the text in a Windows.Forms.Label? Thank you.
Aug 5 '07 #2
Alexey,

You can create a new Font instance which has the FontStyle.Bold value
set and then set the Font property on the label class to that Font instance.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
How to make bold part of the text in a Windows.Forms.Label? Thank you.
Aug 5 '07 #3
Hello Alexey,
How to make bold part of the text in a Windows.Forms.Label? Thank you.
If you need one part of the label bold and teh second normal you'd have to
plit them up into two (or more) labels as far as I can tell...

Jesse
Aug 5 '07 #4
On Aug 5, 9:01 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Alexey,

You can create a new Font instance which has the FontStyle.Bold value
set and then set the Font property on the label class to that Font instance.
In this case the whole text in the label will be bold, I'm right?

Aug 6 '07 #5
On Aug 5, 10:38 pm, Jesse Houwing <Jesse.houw...@nospam-sogeti.nl>
wrote:
Hello Alexey,
How to make bold part of the text in a Windows.Forms.Label? Thank you.

If you need one part of the label bold and teh second normal you'd have to
plit them up into two (or more) labels as far as I can tell...
Hi Jesse

Actually I would like to know if I can do it in the same label,
without having two or more labels.

Cheers!
Aug 6 '07 #6
On 6 Aug., 09:35, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Aug 5, 10:38 pm, Jesse Houwing <Jesse.houw...@nospam-sogeti.nl>
wrote:
Hello Alexey,
How to make bold part of the text in a Windows.Forms.Label? Thank you.
If you need one part of the label bold and teh second normal you'd have to
plit them up into two (or more) labels as far as I can tell...

Hi Jesse

Actually I would like to know if I can do it in the same label,
without having two or more labels.

Cheers!
As far as I know it is not possible to use different fonts for
different parts of the same label, since it doesn't support anything
like RTF markups or the like.
So either you use two labels (one for the bold part, one for the
other) or you derive your own label class from label and handle the
drawing yourself.
I guess personally I would go with deriving in this case, since the
implementation would consist mostly of pretty basic GDI+ stuff and is
more flexible than always creating two labels.

hth,
Kevin Wienhold

Aug 6 '07 #7
On Aug 6, 12:11 pm, KWienhold <hedov...@trashmail.netwrote:
On 6 Aug., 09:35, Alexey Smirnov <alexey.smir...@gmail.comwrote:


On Aug 5, 10:38 pm, Jesse Houwing <Jesse.houw...@nospam-sogeti.nl>
wrote:
Hello Alexey,
How to make bold part of the text in a Windows.Forms.Label? Thank you.
If you need one part of the label bold and teh second normal you'd have to
plit them up into two (or more) labels as far as I can tell...
Hi Jesse
Actually I would like to know if I can do it in the same label,
without having two or more labels.
Cheers!

As far as I know it is not possible to use different fonts for
different parts of the same label, since it doesn't support anything
like RTF markups or the like.
So either you use two labels (one for the bold part, one for the
other) or you derive your own label class from label and handle the
drawing yourself.
I guess personally I would go with deriving in this case, since the
implementation would consist mostly of pretty basic GDI+ stuff and is
more flexible than always creating two labels.

hth,
Kevin Wienhold- Hide quoted text -

- Show quoted text -
Okay, thanks

I have overrided the OnPaint() method

For single line text a code would be something like this

// show first 10 letters in bold

e.Graphics.DrawString(this.Text.Substring(0,9),
new System.Drawing.Font("Tahoma", 8.0F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,
((byte) 0)),
new SolidBrush(this.ForeColor), new
Rectangle(this.Padding.Left, this.Padding.Top, this.Width -
this.Padding.Left, this.Height), StringFormat.GenericDefault);

Size sz = new Size(this.ClientSize.Width, Int32.MaxValue);
sz = TextRenderer.MeasureText(this.Text.Substring(0, 9), this.Font,
sz, TextFormatFlags.WordBreak);

e.Graphics.DrawString(this.Text.Substring(10),
new System.Drawing.Font("Tahoma", 8.0F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)0)),
new SolidBrush(this.ForeColor),
this.Padding.Left + sz.Width, this.Padding.Top);

Aug 6 '07 #8
Yes. I'm rereading the thread (it didn't seem to me that you wanted
part of the text bold from the original post) and if you don't want two
separate labels, then you will have to create a custom control and paint the
label yourself. You will have to change the font which you want placed in
bold, and draw that particular part in bold when you want to.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
On Aug 5, 9:01 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Alexey,

You can create a new Font instance which has the FontStyle.Bold value
set and then set the Font property on the label class to that Font
instance.

In this case the whole text in the label will be bold, I'm right?

Aug 6 '07 #9

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

Similar topics

3
by: TM | last post by:
I have a messagebox and I would like to display a message along with the some selected text I am searching for. But I would like the selected text to appear as bold. I would like my message...
1
by: Li Pang | last post by:
Hi, I have a label box in the form and I want to set some of characters in bold, some body knows that? Thank for advance.
0
by: osmarjunior | last post by:
I'm using a DataGridView in Windows Forms. I made an intelligent search tool that searches in multiple fields, of multiple tables in my database. What I wanna do is make just a part of a cell...
1
by: chris_huh | last post by:
Using the Label Wezard you can easily make labels for all the records in the table, but is there a way to make just one. I have a form that shows the data from a single recordset and on that...
4
by: ravenheart | last post by:
I want to give some emphasis to a Label from gtk, without breaking gnome theme (i.e. not changing colors, etc) I think bolding it would be a good option (could be also underscoring but don't like...
5
by: fidtz | last post by:
Sorry for asking here, but I don't know enough dotnet or Windows programming yet to be very good at googling for answers. OTOH, this is the first question I haven't be able to resolve myself, the...
1
by: Sanjaylml | last post by:
I want to send mail through Docmd.SendObject command in MS Access 2000. Though I set mail message format in Outlook as HTML but still it has no HTML effect. Following is example of code: ...
1
pentahari
by: pentahari | last post by:
I am displays the customer details in listview control using VB6. It displays fine. But particular regular customer record should be display in bold or highlight in listview. Any idea? Advance...
0
by: Bassem | last post by:
Hello, I was wondering if there is an easy way to bold the typed part of suggestions of an AutoCompleteBox. Regards to this link:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.