使用下面的代码我可以绘制箭头形状的按钮(如下所示),但是我想绘制六边形(以下显示为结果图像),以便可以使用png图像大小175x154作为按钮图像,我需要使用什么点来绘制?我需要画6个这样的按钮,我如何实现这一点?用于绘制六角形按钮的要点
private void Parent_Load(object sender, EventArgs e)
{
// Define the points in the polygonal path.
Point[] pts = {
new Point(20, 60),
new Point(140, 60),
new Point(140, 20),
new Point(220, 100),
new Point(140, 180),
new Point(140, 140),
new Point(20, 140)
};
// Make the GraphicsPath.
GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding);
polygon_path.AddPolygon(pts);
// Convert the GraphicsPath into a Region.
Region polygon_region = new Region(polygon_path);
// Constrain the button to the region.
btnExam.Region = polygon_region;
// Make the button big enough to hold the whole region.
btnExam.SetBounds(
btnExam.Location.X,
btnExam.Location.Y,
pts[3].X + 5, pts[4].Y + 5);
}
@Durga看到我的更新。请注意,我的代码是用于“方形按钮”的,如果您想要任何矩形的Button,请告诉我,我将在'GetPoints'方法中稍微修改一下代码。 –
通过使用您的解决方案我得到上面的图像,但上面两个滑动年龄不正确,这些可以纠正和背景空白,我没有得到,为什么btnexam大小会改变,你的意思是如果我需要改变大小正确? – Durga
@Durga不清楚你的意思是“两个滑动年龄......”,因为你的按钮的大小变化,当然向“SizeChanged”事件处理程序添加代码更好,因为如果你想改变你的尺寸按钮,'Region'会相应地为你更新。在某些情况下,更改大小可能会**意外**,并且在这种情况下您的代码不会被破坏。 –