怎么用自己定义的方法来画图形?我想把下面的button_click事件自定义一个方法?因为我想重复调用该方法!可是怎么都不执行结果!求各位高手指点!非常感谢!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Graphics g;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Brush whiteb = new SolidBrush(Color.White);
Pen darkPen = new Pen((Color.Black), 1);
g.DrawEllipse(darkPen, 100, 95, 72, 57);
g.FillEllipse(whiteb, 100, 95, 72, 57);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Graphics g;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Brush whiteb = new SolidBrush(Color.White);
Pen darkPen = new Pen((Color.Black), 1);
g.DrawEllipse(darkPen, 100, 95, 72, 57);
g.FillEllipse(whiteb, 100, 95, 72, 57);
}
}
}
{
Draw();
}
private void Draw()
{
Graphics g = this.CreateGraphics();
Brush whiteb = new SolidBrush(Color.White);
Pen darkp = new Pen(Color.Black, 1);
g.DrawEllipse(darkp, 10, 95, 72, 57);
g.FillEllipse(whiteb, 10, 95, 72, 57);
}
我是新手,不知道是不是这样就行啊?
{
Graphics g = this.CreateGraphics();
Brush whiteb = new SolidBrush(Color.White);
Pen darkPen = new Pen((Color.Black), 1);
g.DrawEllipse(darkPen, 100, 95, 72, 57);
g.FillEllipse(whiteb, 100, 95, 72, 57);
}
这个意思吗 可是不能重复调用哦 并且是窗体生成时就出现这个图了
Graphics g = this.CreateGraphics();
这句改成
Graphics g = e.Graphics;