2016-11-14 1 views
-2

나는이 방법을 사용하려고하지만 textToMark이를 RichTextBox에 표시됩니다 첫 번째 시간을 변경하고 나는 그것이 textToMark가 포함 될 때마다 변경하려면 :굵은 부분은

public static void ChangeTextcolor(string textToMark, Color color, RichTextBox richTextBox) 
    { 
     int startIndex = 0; 

     string text = richTextBox.Text; 
     startIndex = text.IndexOf(textToMark); 

     System.Drawing.Font newFont = new Font("Verdana", 10f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 178, false); 

     try 
     { 
      foreach (string line in richTextBox.Lines) 
      { 
       if (line.Contains(textToMark)) 
       { 
        richTextBox.Select(startIndex, textToMark.Length); 
        richTextBox.SelectionColor = color; 
        richTextBox.SelectionFont = newFont; 
       } 
      } 
     } 
     catch{ } 
    } 

수를 너 나 도와? 감사합니다.

+3

리치 텍스트 상자를 사용하십시오. 더 간단한 TextBox는 개별 단어를 개별적으로 포맷하는 방법이 없습니다. – Steve

+1

대신 RichTextBox를 사용하십시오. 그리고 당신은 아주 열심히 검색하지 않았습니다. –

답변

-1

RichTextBox 컨트롤을 사용할 수 있습니다. Formatting Characters in Bold in a RichTextBox Control (Visual C#)

richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}"; 
+0

감사합니다. 나는 그것을 시도 할 것이다. –

+0

@RonF 도움이 되었습니까? – mybirthname

+0

도움이되었지만 여전히 특정 단어를 굵게 표시하는 방법과 기타 일반 문자를 모두 알 수 없습니다. –