📄 textcolor.cs
字号:
this.mitemBackInfo.Click += new System.EventHandler(this.mitemBackInfo_Click);
//
// mitemBackMenu
//
this.mitemBackMenu.Text = "Menu";
this.mitemBackMenu.Click += new System.EventHandler(this.mitemBackMenu_Click);
//
// mitemBackWindow
//
this.mitemBackWindow.Text = "Window";
this.mitemBackWindow.Click += new System.EventHandler(this.mitemBackWindow_Click);
//
// menuItem9
//
this.menuItem9.MenuItems.Add(this.mitemBackIndigo);
this.menuItem9.MenuItems.Add(this.mitemBackKhaki);
this.menuItem9.MenuItems.Add(this.mitemBackLavender);
this.menuItem9.MenuItems.Add(this.mitemBackMagenta);
this.menuItem9.MenuItems.Add(this.mitemBackNavy);
this.menuItem9.MenuItems.Add(this.mitemBackOlive);
this.menuItem9.MenuItems.Add(this.mitemBackPlum);
this.menuItem9.Text = "Named Colors";
//
// mitemBackIndigo
//
this.mitemBackIndigo.Text = "Indigo";
this.mitemBackIndigo.Click += new System.EventHandler(this.mitemBackIndigo_Click);
//
// mitemBackKhaki
//
this.mitemBackKhaki.Text = "Khaki";
this.mitemBackKhaki.Click += new System.EventHandler(this.mitemBackKhaki_Click);
//
// mitemBackLavender
//
this.mitemBackLavender.Text = "Lavender";
this.mitemBackLavender.Click += new System.EventHandler(this.mitemBackLavender_Click);
//
// mitemBackMagenta
//
this.mitemBackMagenta.Text = "Magenta";
this.mitemBackMagenta.Click += new System.EventHandler(this.mitemBackMagenta_Click);
//
// mitemBackNavy
//
this.mitemBackNavy.Text = "Navy";
this.mitemBackNavy.Click += new System.EventHandler(this.mitemBackNavy_Click);
//
// mitemBackOlive
//
this.mitemBackOlive.Text = "Olive";
this.mitemBackOlive.Click += new System.EventHandler(this.mitemBackOlive_Click);
//
// mitemBackPlum
//
this.mitemBackPlum.Text = "Plum";
this.mitemBackPlum.Click += new System.EventHandler(this.mitemBackPlum_Click);
//
// FormMain
//
this.Controls.Add(this.lblBackB);
this.Controls.Add(this.lblBackG);
this.Controls.Add(this.lblBackR);
this.Controls.Add(this.lblTextB);
this.Controls.Add(this.lblTextG);
this.Controls.Add(this.lblTextR);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Regular);
this.Menu = this.menuMain;
this.MinimizeBox = false;
this.Text = "TextColor";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.FormMain_Paint);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new FormMain());
}
//
// Display color picker dialog -- foreground color
//
private void
mitemTextSetColor_Click(object sender, EventArgs e)
{
ChooseColorDlg ccdlg = new ChooseColorDlg();
ccdlg.Init(this);
if (ccdlg.ShowDialog(ref m_clrText))
{
Invalidate();
DisplayRGBComponents();
}
}
//
// Display color picker dialog -- background color
//
private void
mitemBackgroundSetColor_Click(object sender, EventArgs e)
{
ChooseColorDlg ccdlg = new ChooseColorDlg();
ccdlg.Init(this);
if (ccdlg.ShowDialog(ref m_clrBack))
{
Invalidate();
DisplayRGBComponents();
}
}
// Private data
Color m_clrBack = SystemColors.Window;
Color m_clrText = SystemColors.WindowText;
private void
FormMain_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// The string to draw.
string strDraw = "Text Color";
// String location -- in floating point.
float sinX = 10F;
float sinY = 10F;
// Location as integers.
int x = (int)sinX;
int y = (int)sinY;
// Draw background if needed
if (m_clrBack != SystemColors.Window)
{
// Calculate size of string bounding box.
SizeF size = g.MeasureString(strDraw, Font);
int cx = (int)size.Width;
int cy = (int)size.Height;
// Draw text bounding box.
Rectangle rc = new Rectangle(x, y, cx, cy);
Brush brBack = new SolidBrush(m_clrBack);
g.FillRectangle(brBack, rc);
brBack.Dispose();
}
Brush brText = new SolidBrush(m_clrText);
g.DrawString(strDraw, Font, brText, sinX, sinY);
brText.Dispose();
} // FormMain_Paint
private void DisplayRGBComponents()
{
byte byt = m_clrText.R;
lblTextR.Text = byt.ToString("000");
byt = m_clrText.G;
lblTextG.Text = byt.ToString("000");
byt = m_clrText.B;
lblTextB.Text = byt.ToString("000");
byt = m_clrBack.R;
lblBackR.Text = byt.ToString("000");
byt = m_clrBack.G;
lblBackG.Text = byt.ToString("000");
byt = m_clrBack.B;
lblBackB.Text = byt.ToString("000");
} // DisplayRGBComponents
private void SetTextColor(Color clr)
{
m_clrText = clr;
Invalidate();
DisplayRGBComponents();
}
private void SetBackColor(Color clr)
{
m_clrBack = clr;
Invalidate();
DisplayRGBComponents();
}
private void
mitemTextControlText_Click(object sender, EventArgs e)
{
SetTextColor(SystemColors.ControlText);
}
private void
mitemTextGrayText_Click(object sender, EventArgs e)
{
SetTextColor(SystemColors.GrayText);
}
private void
mitemTextHighlightText_Click(object sender, EventArgs e)
{
SetTextColor(SystemColors.HighlightText);
}
private void
mitemTextInfoText_Click(object sender, EventArgs e)
{
SetTextColor(SystemColors.InfoText);
}
private void
mitemTextMenuText_Click(object sender, EventArgs e)
{
SetTextColor(SystemColors.MenuText);
}
private void
mitemTextWindowText_Click(object sender, EventArgs e)
{
SetTextColor(SystemColors.WindowText);
}
private void
mitemTextAliceBlue_Click(object sender, EventArgs e)
{
SetTextColor(Color.AliceBlue);
}
private void
mitemTextBeige_Click(object sender, EventArgs e)
{
SetTextColor(Color.Beige);
}
private void
mitemTextCoral_Click(object sender, EventArgs e)
{
SetTextColor(Color.Coral);
}
private void
mitemTextDeepPink_Click(object sender, EventArgs e)
{
SetTextColor(Color.DeepPink);
}
private void
mitemTextFireBrick_Click(object sender, EventArgs e)
{
SetTextColor(Color.Firebrick);
}
private void
mitemTextGainsboro_Click(object sender, EventArgs e)
{
SetTextColor(Color.Gainsboro);
}
private void
mitemTextHoneyDew_Click(object sender, EventArgs e)
{
SetTextColor(Color.Honeydew);
}
private void
mitemBackControl_Click(object sender, EventArgs e)
{
SetBackColor(SystemColors.Control);
}
private void
mitemBackHighlight_Click(object sender, EventArgs e)
{
SetBackColor(SystemColors.Highlight);
}
private void
mitemBackInfo_Click(object sender, EventArgs e)
{
SetBackColor(SystemColors.Info);
}
private void
mitemBackMenu_Click(object sender, EventArgs e)
{
SetBackColor(SystemColors.Menu);
}
private void
mitemBackWindow_Click(object sender, EventArgs e)
{
SetBackColor(SystemColors.Window);
}
private void
mitemBackIndigo_Click(object sender, EventArgs e)
{
SetBackColor(Color.Indigo);
}
private void
mitemBackKhaki_Click(object sender, EventArgs e)
{
SetBackColor(Color.Khaki);
}
private void
mitemBackLavender_Click(object sender, EventArgs e)
{
SetBackColor(Color.Lavender);
}
private void
mitemBackMagenta_Click(object sender, EventArgs e)
{
SetBackColor(Color.Magenta);
}
private void
mitemBackNavy_Click(object sender, EventArgs e)
{
SetBackColor(Color.Navy);
}
private void
mitemBackOlive_Click(object sender, EventArgs e)
{
SetBackColor(Color.Olive);
}
private void
mitemBackPlum_Click(object sender, EventArgs e)
{
SetBackColor(Color.Plum);
}
} // class
} // namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -