[英]How to draw graph in c#
我是新手,我不明白为什么这种方法在复制到 Windows 窗体时在运行程序时不起作用。 我是从 MSDN 页面复制的。
public void DrawLinesPoint(PaintEventArgs e)
{
// Create pen.
Pen pen = new Pen(Color.Black, 3);
// Create array of points that define lines to draw.
Point[] points =
{
new Point(10, 10),
new Point(10, 100),
new Point(200, 50),
new Point(250, 300)
};
//Draw lines to screen.
e.Graphics.DrawLines(pen, points);
}
通常,当您在窗体上Paint event
,您会处理窗体的Paint event
并使用PaintEventArgs
的Graphics
属性执行绘图
在您的代码中,您需要先将DrawLinesPoint
添加到绘制事件中,然后才能使用它
在你的Constructor()
添加
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawLinesPoint);
在你的Paint
PaintEventHandler 中
private void DrawLinesPoint(object sender, PaintEventArgs e)
{
Pen pen = new Pen(Color.Black, 3);
// Create array of points that define lines to draw.
Point[] points =
{
new Point(10, 10),
new Point(10, 100),
new Point(200, 50),
new Point(250, 300)
};
//Draw lines to screen.
e.Graphics.DrawLines(pen, points);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.