如何在按下后/再次按/后更改文字颜色?喜欢在视觉中评论。
private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
z++;
if (e.KeyChar == '/')
{
e.Handled = true;
richTextBox1.SelectionColor=Color.Green;
if ((z>1) && (richTextBox1.Text[z - 1] == '/'))
{
richTextBox1.Text += '/'.ToString();
while (e.KeyChar != (char)Keys.Enter)
{
richTextBox1.SelectionColor = Color.Green;
}
}
else
richTextBox1.Text += '/'.ToString();
}
}
答案 0 :(得分:0)
private void richTextBox1_KeyUp(object sender, KeyEventArgs e)
{
if (txtGuid.Text.Contains("//"))
{
txtGuid.ForeColor = Color.Red;
}
}
会起作用
答案 1 :(得分:0)
这可能有效
if(e.KeyChar == (char)Keys.OemBackslash)
{
richTextBox1.ForeColor = System.Drawing.Color.Green;
}