C#学习笔记-自定义控件边框颜色
程序员文章站
2022-03-07 08:31:17
...
label边框
/// <summary>
/// 自定义边框颜色
/// </summary>
public Color BorderColor { get; set; }
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0xf || m.Msg == 0x133)
{
if (this.BorderStyle == BorderStyle.None)
{
System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
Graphics g = Graphics.FromHwnd(m.HWnd);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawRectangle(pen, 0, 0, this.Width -1, this.Height-1);
pen.Dispose();
}
//返回结果
m.Result = IntPtr.Zero;
}
}
richtextbox
/// <summary>
/// 自定义边框颜色
/// </summary>
public Color BorderColor { get; set; }
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0xf || m.Msg == 0x133)
{
if (this.BorderStyle == BorderStyle.None)
{
System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
Graphics g = Graphics.FromHwnd(m.HWnd);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
pen.Dispose();
}
//返回结果
m.Result = IntPtr.Zero;
}
}
textbox
/// <summary>
/// 自定义边框颜色
/// </summary>
public Color BorderColor { get; set; }
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0xf || m.Msg == 0x133)
{
if (this.BorderStyle == BorderStyle.FixedSingle)
{
System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
Graphics g = Graphics.FromHwnd( m.HWnd);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
pen.Dispose();
}
//返回结果
m.Result = IntPtr.Zero;
}
}
comboBox
/// <summary>
/// 自定义边框颜色
/// </summary>
public Color BorderColor { get; set; }
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0xf || m.Msg == 0x133)
{
if (this.FlatStyle == FlatStyle.Flat)
{
System.Drawing.Pen pen = new Pen(this.BorderColor, 1);
Graphics g = Graphics.FromHwnd(m.HWnd);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
pen.Dispose();
}
//返回结果
m.Result = IntPtr.Zero;
}
}
上一篇: lz美容院店长
下一篇: 爆囧,笑出泪花的二货