0
我有這樣的代碼片段:RichTextBox的文本顏色的特定行
if (newLocation.MonsterLivingHere != null)
{
rtbMessages.Text += "You see a " + newLocation.MonsterLivingHere.Name + Environment.NewLine;
}
,我希望「你看(怪物名稱)」是紅色的。
我有幾個地方我想要一個單一的線條是紅色的,但我有很多其他文字在框中,我不想成爲紅色。例如,這段代碼也需要爲紅色:
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));
}
我怎樣才能使文本的一部分紅?
我看不出這是這個問題的副本'http://stackoverflow.com/questions/39085397/highlighting-a-line-in-a-richtextbox1-line-number-a-因爲這個問題有一個不同的變量。如果我錯了,請嘗試以不同的方式解釋答案,因爲我不明白'http://stackoverflow.com/questions/39085397/highlighting-a-line-in-a-richtextbox1-line- number-a-variable' – TheGejr