gpt4 book ai didi

c# - 如何制作非矩形Winform?

转载 作者:行者123 更新时间:2023-11-30 17:22:35 25 4
gpt4 key购买 nike

我正在使用下面的代码来改变 winform 的形状。

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

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

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

最佳答案

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

(您可以使用 xRadiusyRadius 来实现您想要的“圆润度”)

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

关于c# - 如何制作非矩形Winform?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2664754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com