2011-03-15 5 views
0

컨텍스트. 채팅 서버.서식있는 텍스트 상자 글꼴을 선택한 텍스트 글꼴로 바꿈

같은 나는 현재 chatbox 지금은 다른 라인에

Red line 
Green line 

그리고 빨간색 사용자 유형을 2 선이 자신의 글꼴과 색상

가의가 있다고 가정 해 봅시다 가지고 사용자가 필요합니다. RichTextBox 전체가 빨간색이됩니다.

Red line 
Red line //This line was suppose to be green 
Red line 

즉 이것은를 RichTextBox에 새 줄을 추가 내 기능입니다. 문자열은 디버깅 목적으로 사용됩니다.

void OutBox(RichTextBox textBox, string user, string msg, string strFont, string strColour) 
     { 
      int start = textBox.TextLength; 
      textBox.Text += user + " says: " + msg; 
      int end = textBox.TextLength; 
      textBox.Select(start, end - start); 
      Font font = (Font)fc.ConvertFromString(strFont); 
      Color colour = (Color)cc.ConvertFromString(strColour); 
      string s = textBox.SelectedText; 
      textBox.SelectionFont = font; 
      textBox.SelectionColor = colour; 
     } 

잘못된 것이 있습니까? String s은 실제로 실제로 개행 만 선택했음을 보여줍니다.

답변

0
void OutBox(RichTextBox textBox, string user, string msg, string strFont, string strColour) 
     { 
      string s = user + " says: " + msg + "\r"; 
      textBox.AppendText(s); 
      textBox.SelectionStart = textBox.TextLength - s.Length; 
      textBox.SelectionLength = s.Length; 
      Font font = (Font)fc.ConvertFromString(strFont); 
      Color colour = (Color)cc.ConvertFromString(strColour); 
      string s1 = textBox.SelectedText; 
      textBox.SelectionFont = font; 
      textBox.SelectionColor = colour; 
     } 

분명히 textBox.Text 대신에 textBox.AppendText를 사용 + = 문제를 해결합니다.

누구나 알 수 있습니까?

관련 문제