using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace Chart
{
public partial class Chart: UserControl
{
public Chart()
{
InitializeComponent();
init();
}
private void Chart_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Graphics Gp = this.CreateGraphics();
Pen pen = new Pen(Color.Red);
pen.Width = 2;
Point startPoint = new Point(20, 20);
Point endPoint = new Point(70, 20);
Gp.DrawLine(pen, startPoint, endPoint);
}
private void init()
{
Graphics Gp = this.CreateGraphics();
Pen pen = new Pen(Color.Red);
pen.Width = 2;
Point startPoint = new Point(20, 20);
Point endPoint = new Point(70, 20);
Gp.DrawLine(pen, startPoint, endPoint);
}
}
}
启动时
按下button时
为什么init方法无效呢?