문제

C #에서 RichTextBox를 사용하고 있습니다.하나의 RichTextBox 내에서 다른 길이의 문자열을 표시해야하지만이 문자열은 완벽하게 정렬되어야합니다. 이것은 예입니다 ..

abcd   abcde  abcde
ab     abc    abcdef
.

SetW 기능을 사용하여 C ++ 에서이 작업을 수행하는 방법을 알고 있습니다.하지만 C #에서 해당하는 것을 찾을 수 없었습니다.

도움이 되었습니까?

해결책

String.PadRight

innerString.PadRight(10);
.

다른 팁

string varName=String.Format("{0,10:D}", 2);
.

이렇게하면 숫자 2가 오른쪽 정렬 된 폭 10의 문자열로 포맷됩니다. -5를 사용하여 최대 5 ...

출처 : http:///swers.yahoo.com/question/index?qid=.20100727164827AAQJ1HN

나는 그 목적으로 함수를 만들었습니다.

public string tab(string s, int w)
{
    //w is the desired width
    int stringwidth = s.Length;
    int i;
    string resultstring = s;

    for(i=0;i<=(w-stringwidth)/8;i++)
    {
        resultstring = resultstring + "\t";
    }
    return resultstring;
 }
.

그런 다음 ListBox에 추가하십시오 (예 :

listBox.Items.Add(tab("MyFullNameHere",30)+ tab("MyContact - xxxxx",12));
listBox.Items.Add(tab("MyWifeFullNameHereVeryLong", 30) + tab("HerContact - xxxxx", 12));
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top