470,612 Members | 2,456 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,612 developers. It's quick & easy.

How to format a string in resource

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
--
thank you so much for your help
Nov 12 '08 #1
4 3856
On Nov 12, 7:09*pm, clara <cl...@discussions.microsoft.comwrote:
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
--
thank you so much for your help
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
Nov 12 '08 #2
On Nov 12, 8:29*pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Nov 12, 7:09*pm, clara <cl...@discussions.microsoft.comwrote:
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
--
thank you so much for your help

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
Nov 12 '08 #3
Hi Kimiraikkonen,

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

Clara
--
thank you so much for your help
"kimiraikkonen" wrote:
On Nov 12, 7:09 pm, clara <cl...@discussions.microsoft.comwrote:
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
--
thank you so much for your help

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
Nov 12 '08 #4
"clara" <cl***@discussions.microsoft.comschrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 12 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Adam Parkin | last post: by
10 posts views Thread by .Net_Newbie | last post: by
23 posts views Thread by Matt Garman | last post: by
2 posts views Thread by Sam Martin | last post: by
3 posts views Thread by mavrick101 | last post: by
4 posts views Thread by David Morris | last post: by
4 posts views Thread by Peter Larsen [] | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.