How to format a string in resource

C

clara

Hi all,

It may sound esoteric, but actually it is. Let's say there is a string
resource in a project, the value is "AA BB". How can I only format the "BB"
part into bold type. Can I finish the format when I input the string into the
resouce instead of using coding?

Clara
 
K

kimiraikkonen

Hi all,

It may sound esoteric, but actually it is. Let's say there is a string
resource in a project, the value is "AA  BB". How can I only format the"BB"
part into bold type. Can I finish the format when I input the string intothe
resouce instead of using coding?

Clara

Hi Clara,
After you added your string into your resource(Through Project
Settings -> Resources), let's say it's named as "String1" and its
value is "AA BB", you can get the last two letter using substring
function, that is "BB", then make it bold using a new font instance,
and finally bring AA next to BB using two seperate controls. (in that
sample, a label).

However, the part that i wonder and have to guess is that if you're
using a Label or other control to show your string. For instance, if
you want to show your string in your label with formatting(making
bold) the "AA" part, i'm afraid you need to use 2 labels and first one
will show "AA" and the other one will show "BB", and you need to bring
Label2(which holds BB) next to Label1 in designer.

So the code that i wrote as what i understood from your issue:

' Keep "AA" as original without making bold
' Optionaly make AA's size same as BB
Label1.Font = New Font("Arial", 10, FontStyle.Regular)
Label1.Text = My.Resources.String1.Substring(0, 2)

' Set BB's font to bold
Label2.Font = New Font("Arial", 10, FontStyle.Bold)
Label2.Text = My.Resources.String1.Substring(3, 2)
' That code brings Label2 next to Label1
' to have a display as if AA and BB are together.
Label2.Location = New Point(Label1.Location.X + Label1.Width,
Label2.Location.Y)

I'm not sure if this is what you're looking for, but i hope it makes
some sense to make you think of the steps that you can take.

Onur Güzel
 
K

kimiraikkonen

Hi Clara,
After you added your string into your resource(Through Project
Settings -> Resources), let's say it's named as "String1" and its
value is "AA BB", you can get the last two letter using substring
function, that is "BB", then make it bold using a new font instance,
and finally bring AA next to BB using two seperate controls. (in that
sample, a label).

However, the part that i wonder and have to guess is that if you're
using a Label or other control to show your string. For instance, if
you want to show your string in your label with formatting(making
bold) the "AA" part, i'm afraid you need to use 2 labels and first one
will show "AA" and the other one will show "BB", and you need to bring
Label2(which holds BB) next to Label1 in designer.

So the code that i wrote as what i understood from your issue:

' Keep "AA" as original without making bold
' Optionaly make AA's size same as BB
Label1.Font = New Font("Arial", 10, FontStyle.Regular)
Label1.Text = My.Resources.String1.Substring(0, 2)

' Set BB's font to bold
Label2.Font = New Font("Arial", 10, FontStyle.Bold)
Label2.Text = My.Resources.String1.Substring(3, 2)
' That code brings Label2 next to Label1
' to have a display as if AA and BB are together.
Label2.Location = New Point(Label1.Location.X + Label1.Width,
Label2.Location.Y)

I'm not sure if this is what you're looking for, but i hope it makes
some sense to make you think of the steps that you can take.

Onur Güzel

I want to update the last line, assuming your labels' initial
positions are different in designer and that would be more useful:

Label2.Location = New Point(Label1.Location.X + Label1.Width, _
Label1.Location.Y)

Again, positioning algorithm depends how you and what you use to
display your strings and i assumed you're using them on your form, eg:
using a label.

HTH,

Onur Güzel
 
C

clara

Hi Kimiraikkonen,

Thank you very much for your edifying reply! It helps me much!

Clara
 
H

Herfried K. Wagner [MVP]

clara said:
It may sound esoteric, but actually it is. Let's say there is a string
resource in a project, the value is "AA BB". How can I only format the
"BB"
part into bold type. Can I finish the format when I input the string into
the
resouce instead of using coding?

You could format the string using RTF codes and then use the RichTextBox
control to display the string.
 

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