how to color one word of text in a FCTB (Fast Color Text Box)
Możesz też użyć :
richTextBox-a
Color specific words in RichtextBox
Np.:
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
this.CheckKeyword("kolor", Color.Purple, 0);
}
private void CheckKeyword(string word, Color color, int startIndex)
{
if (this.richTextBox1.Text.Contains(word))
{
int index = -1;
int selectStart = this.richTextBox1.SelectionStart;
while ((index = this.richTextBox1.Text.IndexOf(word, (index + 1))) != -1)
{
this.richTextBox1.Select((index + startIndex), word.Length);
this.richTextBox1.SelectionColor = color;
this.richTextBox1.Select(selectStart, 0);
this.richTextBox1.SelectionColor = Color.Black;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.Text = "jak zmienić kolor tylko jednego słowa";
}
}
}
