本文整理汇总了C#中System.Windows.Forms.RichTextBox.ResetBackColor方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.ResetBackColor方法的具体用法?C# RichTextBox.ResetBackColor怎么用?C# RichTextBox.ResetBackColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.ResetBackColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadOnly_BackColor_Set
public void ReadOnly_BackColor_Set ()
{
RichTextBox rtb = new RichTextBox ();
rtb.BackColor = Color.Blue;
rtb.ReadOnly = true;
Assert.IsTrue (rtb.ReadOnly, "#A1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#A2");
Form form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (rtb);
form.Show ();
Assert.IsTrue (rtb.ReadOnly, "#B1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#B2");
rtb.ReadOnly = false;
Assert.IsFalse (rtb.ReadOnly, "#C1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#C2");
rtb.ReadOnly = true;
Assert.IsTrue (rtb.ReadOnly, "#D1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#D2");
rtb.BackColor = Color.Red;
Assert.IsTrue (rtb.ReadOnly, "#E1");
Assert.AreEqual (Color.Red, rtb.BackColor, "#E2");
rtb.ReadOnly = false;
Assert.IsFalse (rtb.ReadOnly, "#F1");
Assert.AreEqual (Color.Red, rtb.BackColor, "#F2");
rtb.ReadOnly = true;
rtb.ResetBackColor ();
Assert.IsTrue (rtb.ReadOnly, "#G1");
#if NET_2_0
Assert.AreEqual (SystemColors.Control, rtb.BackColor, "#G2");
#else
Assert.AreEqual (SystemColors.Window, rtb.BackColor, "#G2");
#endif
form.Dispose ();
rtb = new RichTextBox ();
rtb.ReadOnly = true;
rtb.BackColor = Color.Blue;
Assert.IsTrue (rtb.ReadOnly, "#H1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#H2");
form = new Form ();
form.ShowInTaskbar = false;
form.Controls.Add (rtb);
form.Show ();
Assert.IsTrue (rtb.ReadOnly, "#I1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#I2");
rtb.ReadOnly = false;
Assert.IsFalse (rtb.ReadOnly, "#J1");
Assert.AreEqual (Color.Blue, rtb.BackColor, "#J2");
rtb.ResetBackColor ();
Assert.IsFalse (rtb.ReadOnly, "#K1");
Assert.AreEqual (SystemColors.Window, rtb.BackColor, "#K2");
form.Close ();
}
示例2: HighlightSimpleSetting
/// <summary>
/// Highlights rich text box with simple setting definition string.
/// </summary>
public static void HighlightSimpleSetting(
RichTextBox rich,
ITextValidator textValidator,
ICharValidator charValidator)
{
if (textValidator.IsValidText(rich.Text))
{
rich.ResetBackColor();
}
else
{
rich.BackColor = Colors.LightRed;
}
int current = 0;
foreach (string line in rich.Lines)
{
for (int i = 0; i < line.Length; i++)
{
if (!charValidator.IsValidChar(line[i]))
{
rich.SelectionStart = current + i;
rich.SelectionLength = 1;
rich.SelectionColor = Color.Red;
}
}
current += line.Length + 1;
}
}