C# panel边框设置 请问一下这个panel的边框是怎么设置的? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果确有虚线,自己画的,OnPaint中画个巨型,极其简单 没有外面那个虚线,那个事截图的效果只是里面的那个panel的白色的那个边框 ControlPaint.DrawBorder(e.Graphics, panel.ClientRectangle,Color.Gray,3, ButtonBorderStyle.Solid,Color.Gray,3, ButtonBorderStyle.Solid,Color.Gray,3, ButtonBorderStyle.Solid,Color.Gray,3, ButtonBorderStyle.Solid);你是说这样么?可是达不到那种有点立体的边框效果啊 // 楼主需要一件事情,那就是:任何控件所呈现的外观都是画出来的。// 所以,边框当然也是画出来的。// 楼主可以自己写一个 Class,继承自 Control 类,然后重写 OnPaint 事件。// 建议在 base.OnPaint(e) 之后写自己的 Custom 代码。protected override void OnPaint(PaintEventArgs e){ base.OnPaint(e); // your code}// 楼主的图看的不是很清楚,根据自己的分析,下面画出来的这个效果应该可以满足楼主的需要。protected override void OnPaint(System.Windows.Forms.PaintEventArgs e){ base.OnPaint(e); Color color1 = Color.FromArgb(173, 170, 173); Color color2 = Color.White; int border1 = 1; int border2 = 2; Rectangle rect1 = new Rectangle(0, 0, ClientSize.Width - 3, ClientSize.Height - 3); Rectangle rect2 = new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1); using (var pen1 = new Pen(color1)) using (var pen2 = new Pen(color2, 2.0F) { Alignment = PenAlignment.Inset }) { e.Graphics.DrawRectangle(pen2, rect2); e.Graphics.DrawRectangle(pen1, rect1); }} 恩,楼上的看起来应该可以满足我的需求,不过我还没有试过。我刚刚这样子基本上实现了我的要求 private void panel1_Paint(object sender, PaintEventArgs e) { Panel pnl = (Panel)sender; var BorderWidth = 2; //BevelOuter (bvLowered) e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), 0, 0, 0, pnl.Height - 0); e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), 0, 0, pnl.Width - 0, 0); e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), pnl.Width - 1, pnl.Height - 1, 0, pnl.Height - 1); e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), pnl.Width - 1, pnl.Height - 1, pnl.Width - 1, 0); if (BorderWidth > 0) { //BevelInner (bvRaised) e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), BorderWidth, BorderWidth, BorderWidth, pnl.Height - BorderWidth); e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), BorderWidth, BorderWidth, pnl.Width - BorderWidth, BorderWidth); e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), pnl.Width - (BorderWidth + 1), pnl.Height - (BorderWidth + 1), BorderWidth, pnl.Height - (BorderWidth + 1)); e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), pnl.Width - (BorderWidth + 1), pnl.Height - (BorderWidth + 1), pnl.Width - (BorderWidth + 1), BorderWidth); } } C# 读取 XML 问题 ( 急) 高手进 正则表达式或略空格、换行 WPF listview 问题 如何理解反序列化的几个参数? 关于comboBox的问题(新) 请教下面用thread 和不用thread有什么本质区别阿 一个用C#编写的扑克牌网络游戏: 板子炮网络大战,欢迎下载! 动态创建Acees工作表遇到奇怪的问题 从集合中提取符合条件的记录 得到DataGrid的例的例的順序 在线等:OleDbException (0x80004005): Disk or network error错误 C#新手求助!!!!!!
只是里面的那个panel的白色的那个边框
ControlPaint.DrawBorder(e.Graphics, panel.ClientRectangle,Color.Gray,3,
ButtonBorderStyle.Solid,Color.Gray,3,
ButtonBorderStyle.Solid,Color.Gray,3,
ButtonBorderStyle.Solid,Color.Gray,3,
ButtonBorderStyle.Solid);
你是说这样么?
可是达不到那种有点立体的边框效果啊
// 楼主需要一件事情,那就是:任何控件所呈现的外观都是画出来的。
// 所以,边框当然也是画出来的。
// 楼主可以自己写一个 Class,继承自 Control 类,然后重写 OnPaint 事件。
// 建议在 base.OnPaint(e) 之后写自己的 Custom 代码。protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// your code
}// 楼主的图看的不是很清楚,根据自己的分析,下面画出来的这个效果应该可以满足楼主的需要。
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e); Color color1 = Color.FromArgb(173, 170, 173);
Color color2 = Color.White; int border1 = 1;
int border2 = 2; Rectangle rect1 = new Rectangle(0, 0, ClientSize.Width - 3, ClientSize.Height - 3);
Rectangle rect2 = new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1); using (var pen1 = new Pen(color1))
using (var pen2 = new Pen(color2, 2.0F) { Alignment = PenAlignment.Inset })
{
e.Graphics.DrawRectangle(pen2, rect2);
e.Graphics.DrawRectangle(pen1, rect1);
}
}
恩,楼上的看起来应该可以满足我的需求,不过我还没有试过。我刚刚这样子基本上实现了我的要求 private void panel1_Paint(object sender, PaintEventArgs e)
{
Panel pnl = (Panel)sender;
var BorderWidth = 2; //BevelOuter (bvLowered)
e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), 0, 0, 0, pnl.Height - 0);
e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), 0, 0, pnl.Width - 0, 0);
e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), pnl.Width - 1, pnl.Height - 1, 0, pnl.Height - 1);
e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), pnl.Width - 1, pnl.Height - 1, pnl.Width - 1, 0); if (BorderWidth > 0)
{
//BevelInner (bvRaised)
e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), BorderWidth, BorderWidth, BorderWidth, pnl.Height - BorderWidth);
e.Graphics.DrawLine(new Pen(SystemColors.ControlLightLight), BorderWidth, BorderWidth, pnl.Width - BorderWidth, BorderWidth);
e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), pnl.Width - (BorderWidth + 1), pnl.Height - (BorderWidth + 1), BorderWidth, pnl.Height - (BorderWidth + 1));
e.Graphics.DrawLine(new Pen(SystemColors.ControlDark), pnl.Width - (BorderWidth + 1), pnl.Height - (BorderWidth + 1), pnl.Width - (BorderWidth + 1), BorderWidth);
}
}