如何使一个非矩形的WinForms? [英] How to make a Non Rectangular Winforms?
本文介绍了如何使一个非矩形的WinForms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码更改为在WinForm的形状。
它改变形状,但不喜欢我怎么想。
我需要的形式有弯曲的角落。
我应该使用什么样的点,怎么做呢?
公共无效MakeNonRectangularForm()
{
System.Drawing.Drawing2D.GraphicsPath p =新System.Drawing.Drawing2D.GraphicsPath();
INT宽度= this.ClientSize.Width;
INT高度= this.ClientSize.Height;
p.AddClosedCurve(新点[] {新点(宽度/ 2,高度/ 2),
新点(宽度,0),新的点(宽度,高度/ 3),
新点(宽度宽/ 3,高度),
新点(宽/ 7,高度高/ 8)});
this.Region =新区(p);
}
解决方案
下面是一些代码,我已经使用之前创建圆边,使用 AddArc
和线条拼凑边框:
(你可以玩与 xRadius
和 YRadius为
来达到您想要的四舍五入性量)
INT xRadius = {插入值这里};
INT YRadius为= {此处插入值};
GraphicsPath的边缘=新的GraphicsPath();
INT rightHandLeft = this.Width - xRadius - 1;
INT bottomSideTop = this.Height - YRadius为 - 1;
edge.AddArc(0,0,xRadius,YRadius为,180,90);
edge.AddLine(xRadius,0,rightHandLeft,0);
edge.AddArc(rightHandLeft,0,xRadius,YRadius为,270,90);
edge.AddLine(this.Width,YRadius为,this.Width,bottomSideTop);
edge.AddArc(rightHandLeft,bottomSideTop,xRadius,YRadius为0,90);
edge.AddLine(rightHandLeft,this.Height,xRadius,this.Height);
edge.AddArc(0,bottomSideTop,xRadius,YRadius为,90,90);
edge.AddLine(0,bottomSideTop,0,YRadius为);
this.Region =新的地区(边);
I am using the below code to change to shape of the winform. Its changing the shape, but not like how i wanted. I need the forms to have curved corners.
What points should i use to get it ?
public void MakeNonRectangularForm()
{
System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath();
int width = this.ClientSize.Width;
int height = this.ClientSize.Height;
p.AddClosedCurve(new Point[]{new Point(width/2, height/2),
new Point(width,0), new Point(width, height/3),
new Point(width-width/3, height),
new Point(width/7, height-height/8)});
this.Region = new Region(p);
}
解决方案
The following is some code I have used to create rounded edges before, using AddArc
and lines to piece together the border:
(You can play with xRadius
and yRadius
to achieve your desired amount of "rounded-ness")
int xRadius = {insert value here};
int yRadius = {insert value here};
GraphicsPath edge = new GraphicsPath();
int rightHandLeft = this.Width - xRadius - 1;
int bottomSideTop = this.Height - yRadius - 1;
edge.AddArc(0, 0, xRadius, yRadius, 180, 90);
edge.AddLine(xRadius, 0, rightHandLeft, 0);
edge.AddArc(rightHandLeft, 0, xRadius, yRadius, 270, 90);
edge.AddLine(this.Width, yRadius, this.Width, bottomSideTop);
edge.AddArc(rightHandLeft, bottomSideTop, xRadius, yRadius, 0, 90);
edge.AddLine(rightHandLeft, this.Height, xRadius, this.Height);
edge.AddArc(0, bottomSideTop, xRadius, yRadius, 90, 90);
edge.AddLine(0, bottomSideTop, 0, yRadius);
this.Region = new Region(edge);
这篇关于如何使一个非矩形的WinForms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文