2016-11-19 1 views
0

색상.를 RichTextBox 텍스트 내가이 코드 조각이 특정 라인

나는 한 줄을 빨간색으로하고 싶지만 빨간색으로되고 싶지 않은 상자에는 다른 많은 텍스트가 있습니다. 예를 들어이 코드는 빨간색이어야합니다.

if(_player.CurrentHitPoints <= 0) 
{ 
    //Display a dead message 
    rtbMessages.Text = " " + Environment.NewLine; 
    rtbMessages.Text += "The " + _currentMonster.Name + " killed you." + Environment.NewLine; 
    //Moves the player to "Home" 
    MoveTo(World.LocationByID(World.LOCATION_ID_HOME)); 
} 

텍스트의 일부만을 빨간색으로 만들려면 어떻게해야합니까?

+0

I는이 질문의 중복 표시되지 않습니다'http://stackoverflow.com/questions/39085397/highlighting-a-line-in-a-richtextbox1-line-number-a- 변수 '라는 질문이 있기 때문에 다른 것입니다. 내가 틀렸다면 해답을 다른 방법으로 설명해주십시오. 왜냐하면'http://stackoverflow.com/questions/39085397/highlighting-a-line-in-a-textbox1-line- number-a-variable' – TheGejr

답변

0

선택 색상을 설정하면 다음 삽입이 해당 색상으로됩니다 (예 :

Color current = rtbMessages.SelectionColor; 

rtbMessages.SelectionColor = Color.Red; 
rtbMessages.AppendText("I am red" + Environment.NewLine); 

rtbMessages.SelectionColor = Color.Blue; 
rtbMessages.AppendText("I am blue" + Environment.NewLine); 

rtbMessages.SelectionColor = current; 
rtbMessages.AppendText("I am whatever colour was set before red"); 
+0

나는 지금이 글을 썼지 만 'SelectionColor'나 'AppendText'도 파란색이 아니며 클래스 나 refrence가 누락 되었습니까? 텍스트가 색상을 변경하지 않습니다. – TheGejr

관련 문제