如何重写panel边框 panel边框设置成SingleLine后只有一种颜色黑色,我想换成别的颜色,但又不想用第三方控件,请教如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置this.panel1.BorderStyle = BorderStyle.None;private void panel1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawRectangle(new Pen(Brushes.Red), new Rectangle(0, 0, this.panel1.Width - 1, this.panel1.Height - 1)); } 这样有个问题,当panel有滚动条,滑动滚动条时,就会重绘在错误的位置,多出很多条竖线来 public class MyPanel : Panel { Color _BorderColor = Color.Blue; public Color BorderColor { get { return _BorderColor; } set { _BorderColor = value; } } [DllImport("user32.dll")] static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32.dll")] public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); protected override void WndProc(ref Message m) { if (m.Msg == 0x85) { IntPtr hdc = GetWindowDC(Handle); Graphics g = Graphics.FromHdc(hdc); Pen pen = new Pen(_BorderColor, 2); try { Rectangle rect = Bounds; rect.Offset(-rect.Location.X, -rect.Location.Y); g.DrawRectangle(pen, rect); } finally { g.Dispose(); ReleaseDC(Handle, hdc); } } else base.WndProc(ref m); } } 怎么定义一个ASCII值,在转换成16进制。 在把它作为命令发送给串口。 关于c# winform 与串口的问题?????? C#导出XML问题(急,在线等) C#里时关闭子窗口时base.Dispose(disposing)报错 pdf文档修改问题 DataGrid模板列按钮取值问题 50分求c#.net如何实现接收传真 进来看下这段代码为什么不能实现。我的方法有问题 spread控件中如何才能做到双击单元格,选择其中的数据? c#高手看过来!!!!!!!! 请教,关于datagridview某列动态添加checkbox控件的问题 正则表达式 找出平局的比分
设置this.panel1.BorderStyle = BorderStyle.None;private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Brushes.Red), new Rectangle(0, 0, this.panel1.Width - 1, this.panel1.Height - 1));
}
public class MyPanel : Panel
{
Color _BorderColor = Color.Blue; public Color BorderColor
{
get
{
return _BorderColor;
}
set
{
_BorderColor = value;
}
} [DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); protected override void WndProc(ref Message m)
{
if (m.Msg == 0x85)
{
IntPtr hdc = GetWindowDC(Handle);
Graphics g = Graphics.FromHdc(hdc);
Pen pen = new Pen(_BorderColor, 2);
try
{
Rectangle rect = Bounds;
rect.Offset(-rect.Location.X, -rect.Location.Y);
g.DrawRectangle(pen, rect);
}
finally
{
g.Dispose();
ReleaseDC(Handle, hdc);
}
}
else
base.WndProc(ref m);
}
}