如何创建多边形自定义控件 [英] How to create polygon custom controls

查看:108
本文介绍了如何创建多边形自定义控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨frds,



是c#的新人。现在很难创建自定义控件。现在创建 多边形控件如traingle,hexagon,pentagon等等。请帮助我解决麻烦。这将有助于我的载体。请帮助我



提前感谢

hi frds,

am new one to c#.Now am troubling to create custom control.preciously create polygon controls like traingle,hexagon,pentagon and so on.pls help me to break my trouble.It will help to my carrier.pls help me

thanks in advance

推荐答案

如果你的意思是如何创建一个多边形而不是矩形的自定义控件?

然后它非常简单:在它的构造函数中将Region Property设置为你想要的形状:

If you mean "how do I create a custom control that is polygonal rather than rectangular?"
Then it's surprisingly easy: in it's constructor set the Region Property to the shape you want:
GraphicsPath path = new GraphicsPath();
path.AddLines(new Point[] { new Point(0,0), new Point(Width, 0), new Point(Width / 2, Height), new Point(0,0)});
Region = new Region(path);

例如,创建一个三角形。

Creates a triangle, for example.


下面是如何使用c#绘制多边形的示例。





Below is the sample how to draw a Polygon by using c#.


public void DrawPolygonPoint(PaintEventArgs e)
{

    // Create pen.
    Pen blackPen = new Pen(Color.Black, 3);

    // Create points that define polygon.
    Point point1 = new Point(50,  50);
    Point point2 = new Point(100,  25);
    Point point3 = new Point(200,   5);
    Point point4 = new Point(250,  50);
    Point point5 = new Point(300, 100);
    Point point6 = new Point(350, 200);
    Point point7 = new Point(250, 250);
    Point[] curvePoints =
             {
                 point1,
                 point2,
                 point3,
                 point4,
                 point5,
                 point6,
                 point7
             };

    // Draw polygon to screen.
    e.Graphics.DrawPolygon(blackPen, curvePoints);
}





欲了解更多信息:Polygon



另一个链接: SOF



我希望这会对你有所帮助。



For more info :Polygon

Another link : SOF

I hope this will help to you.


这篇关于如何创建多边形自定义控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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