How to format a string in resource

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Y2xhcmE=?=

    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
  • kimiraikkonen

    #2
    Re: How to format a string in resource

    On Nov 12, 7:09 pm, clara <cl...@discussi ons.microsoft.c omwrote:
    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(Throug h 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(maki ng
    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.Regul ar)
    Label1.Text = My.Resources.St ring1.Substring (0, 2)

    ' Set BB's font to bold
    Label2.Font = New Font("Arial", 10, FontStyle.Bold)
    Label2.Text = My.Resources.St ring1.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.Lo cation.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


    Comment

    • kimiraikkonen

      #3
      Re: How to format a string in resource

      On Nov 12, 8:29 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
      On Nov 12, 7:09 pm, clara <cl...@discussi ons.microsoft.c omwrote:
      >
      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(Throug h 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(maki ng
      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.Regul ar)
      Label1.Text = My.Resources.St ring1.Substring (0, 2)
      >
      ' Set BB's font to bold
      Label2.Font = New Font("Arial", 10, FontStyle.Bold)
      Label2.Text = My.Resources.St ring1.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.Lo cation.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.Lo cation.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

      Comment

      • =?Utf-8?B?Y2xhcmE=?=

        #4
        Re: How to format a string in resource

        Hi Kimiraikkonen,

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

        Clara
        --
        thank you so much for your help


        "kimiraikko nen" wrote:
        On Nov 12, 7:09 pm, clara <cl...@discussi ons.microsoft.c omwrote:
        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(Throug h 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(maki ng
        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.Regul ar)
        Label1.Text = My.Resources.St ring1.Substring (0, 2)
        >
        ' Set BB's font to bold
        Label2.Font = New Font("Arial", 10, FontStyle.Bold)
        Label2.Text = My.Resources.St ring1.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.Lo cation.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
        >
        >
        >

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: How to format a string in resource

          "clara" <clara@discussi ons.microsoft.c omschrieb:
          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/>

          Comment

          Working...