CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Why when I add a space to the Label string heterogeneous length of the string ?

  1. #1
    Join Date
    Sep 2007
    Posts
    378

    Why when I add a space to the Label string heterogeneous length of the string ?

    Suppose I have 4 Label.Text corresponding to 4 series: Basic salary, Business salary, Responsibility allowance, Attraction allowance. When running the program I can change the string "Responsibility allowance" with another string "Attribution allowance" for example. I take the basic salary series as the standard for other series, from the basic salary series, find the 2-dot character position ":" is position 36 through the function Label1.Text.IndexOf (":"). The other strings that are inserted at the run are "Responsibility allowance" and "Attraction allowance" string, to display four strings uniformly with a 2-dot ":". I insert a space in the string so that the string length at the 2-dot character is equal to the 36th position but when displaying the characters at position 36 as the 2-dot is not equal, I see if the character is different if white characters are less often inserted in string will re-attach, why is that? you see my photo file. How do I write code to overcome this situation ?
    http://www.mediafire.com/view/0t4b8j...Space.jpg/file

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,844

    Re: Why when I add a space to the Label string heterogeneous length of the string ?

    Quote Originally Posted by dongtrien View Post
    Please, attach your image to your post! Use this toolbar button:
    Attachment 35909
    Victor Nijegorodov

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,360

    Re: Why when I add a space to the Label string heterogeneous length of the string ?

    : is called a colon. As for your question, I'm not sure if you are talking about the actual position or the visible position. Based on your image those colons line up on all but 1 entry but if they were all in position 36 of the string then they would not line up on the display. Keep in mind that you are using a proportional font so some letters are wider than others and therefore you can not count on lining up any character at a give position especially 36 characters in, to much variation in character widths.
    If you use a fixed font then all characters including spaces take up the same width and they will line up perfectly.

    List of the left uses default proportional font, list on the right uses fixed font. Both have exactly the same text in them.

    Name:  Image1.jpg
Views: 17
Size:  8.8 KB
    Last edited by DataMiser; October 30th, 2020 at 06:23 PM.
    Always use [code][/code] tags when posting code.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,399

    Re: Why when I add a space to the Label string heterogeneous length of the string ?

    Another approach is to make all text labels the same width and to right justify (i.e. align) the text. Then, the text will always align to the right regardless of hiw long the text strings are.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)