c#绘制窗体边框 我把窗体的FormborderStyle设为了None,想给窗体绘制个黑色边框,四个角是弧形,本人新手,在线等,有合适的分数全部相送 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个问题真是困扰不少人,包括我,搞了好久重写WndProc方法,用API获取Windows消息绘制窗体的非客户区,网上没有找到C#的例子现在只有找一下C++的,查一下Win32编程的资料,可能会有所启发用API函数SystemParametersInfo获取Windows工作区的大小,然后给窗体的MaximumSize属性赋值,限定窗体的最大Size,这样就不会盖住任务栏了。 绘制4个圆角代码: public static Region CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse) { GraphicsPath path = new GraphicsPath(); path.AddArc(new Rectangle(nLeftRect, nTopRect, nWidthEllipse, nHeightEllipse), 180f, 90f); path.AddArc(new Rectangle((nRightRect - nWidthEllipse) - 1, nTopRect, nWidthEllipse, nHeightEllipse), -90f, 90f); path.AddArc(new Rectangle((nRightRect - nWidthEllipse) - 1, (nBottomRect - nHeightEllipse) - 1, nWidthEllipse, nHeightEllipse), 0f, 90f); path.AddArc(new Rectangle(nLeftRect, (nBottomRect - nHeightEllipse) - 1, nWidthEllipse, nHeightEllipse), 90f, 90f); path.CloseAllFigures(); return new Region(path); }form1.Region = CreateRoundRectRgn(this.sideWidth, this.formTopOffset, (this.frmBase.ClientSize.Width + this.sideWidth) + 1, (this.frmBase.Height - this.sideWidth) + 1, RoundWidth, RoundHeight); 3楼已经给了大概思路,你再仔细调试一下,保证GraphicsPath是一个封闭的路径,貌似楼上给的代码不能保证生成封闭路径。然后在OnPaint当中画你的圆角。 你首先要明白什么是GraphicPath,Region,这类的概念。解决这个问题的本质就是给Form.Region设置一个合适的区域,啥意思呢,本来Form的外观是个矩形,现在为了解决的问题,四个角成了圆角,那么这个矩形必须将矩形的四个角裁剪成四个圆角,这就是Form.Region做的事情,而要构成四个角被裁剪成圆角的样子,那么你必须使用GraphicPath来创建一条路径,你想象一下,一笔画成一条你想要的Form的边框(四个角是圆角)应该怎么做,这个GraphicPath就做这个的。 两个线程,以写一个TXT,另一个读出该TXT的数据,总是冲突,求救啊。 请教一个简单的问题 invoke 界面冻结问题 关于hook键盘 VS2010 C# 添加 DLL 引用失败 请问怎样将ACCESS版本的系统转为SQL版本的 什么是标准差啊? 问一个查询语句 winform窗口问题? 求助:我怎么实现在sql server里 写log?并且能方便查询,用c#做报表? 在写一框架的时候首先要写什么程序文档,之类的问题 根据GPS记录计算统计车辆里程算法.
重写WndProc方法,用API获取Windows消息绘制窗体的非客户区,网上没有找到C#的例子
现在只有找一下C++的,查一下Win32编程的资料,可能会有所启发用API函数SystemParametersInfo获取Windows工作区的大小,然后给窗体的MaximumSize属性赋值,限定窗体的最大Size,这样就不会盖住任务栏了。
public static Region CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse)
{
GraphicsPath path = new GraphicsPath();
path.AddArc(new Rectangle(nLeftRect, nTopRect, nWidthEllipse, nHeightEllipse), 180f, 90f);
path.AddArc(new Rectangle((nRightRect - nWidthEllipse) - 1, nTopRect, nWidthEllipse, nHeightEllipse), -90f, 90f);
path.AddArc(new Rectangle((nRightRect - nWidthEllipse) - 1, (nBottomRect - nHeightEllipse) - 1, nWidthEllipse, nHeightEllipse), 0f, 90f);
path.AddArc(new Rectangle(nLeftRect, (nBottomRect - nHeightEllipse) - 1, nWidthEllipse, nHeightEllipse), 90f, 90f);
path.CloseAllFigures();
return new Region(path);
}form1.Region = CreateRoundRectRgn(this.sideWidth, this.formTopOffset, (this.frmBase.ClientSize.Width + this.sideWidth) + 1, (this.frmBase.Height - this.sideWidth) + 1, RoundWidth, RoundHeight);