怎么用自己定义的方法来画图形?我想把下面的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);
       }
    }
}

解决方案 »

  1.   

      private void button1_Click(object sender, EventArgs e)
            {
                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);
          }
    我是新手,不知道是不是这样就行啊?
      

  2.   

    你最好在OnPaint中画,因为涉及到重绘,否则图像会被擦出的,draw方法接收一个参数,类型为 Graphics ,将OnPaint中的e.Graphics 传给Draw
      

  3.   

             private void Form1_Paint(object sender, PaintEventArgs 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);
            }
    这个意思吗 可是不能重复调用哦 并且是窗体生成时就出现这个图了 
      

  4.   

    嗯 我试试吧 thankyou 我也初学 不咋懂哦
      

  5.   


    Graphics g = this.CreateGraphics();
    这句改成
    Graphics g = e.Graphics;