如何制作非矩形Winform? [英] How to make a Non Rectangular Winform?

查看:52
本文介绍了如何制作非矩形Winform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码来更改winform的形状.

它正在改变形状,但不像我想要的那样.我需要表格有弯角.

我应该使用什么积分来获得它?

 公共无效的MakeNonRectangularForm(){var p = new GraphicsPath();int width = ClientSize.Width;int height = ClientSize.Height;p.AddClosedCurve(new Point [] {new Point(width/2,height/2),新Point(width,0),new Point(width,height/3),新点(宽度-宽度/3,高度),新Point(宽度/7,高度-高度/8)});区域=新区域(p);} 

解决方案

以下是我以前用来创建圆角的一些代码,这些代码使用 AddArc 和线条拼凑边框:

(您可以使用 xRadius yRadius 来达到所需的圆角度")​​

  int xRadius = {在此处插入值};int yRadius = {在此处插入值};GraphicsPath edge =新的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); 

I am using the code below to change to shape of the winform.

It's changing the shape, but not like how I wanted. I need the form to have curved corners.

What points should I use to get it?

public void MakeNonRectangularForm()
{
    var p = new GraphicsPath();

    int width  = ClientSize.Width;
    int height = 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)});

    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);

这篇关于如何制作非矩形Winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆