472,780 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 30690
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.