例如在panel1上画一个圆心为(x,y)半径为z的圆~~请问怎么才能做到?谢谢啦~~~

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using System.Windows.Forms;class Form1 : Form
    {
      Form1()
      {
        Panel panel1  = new Panel();
        panel1.Parent = this;
        panel1.Dock   = DockStyle.Fill;
        panel1.Paint += delegate(object o, PaintEventArgs e)
        {
          // 画一个圆心为(x,y)半径为z的圆
          float x = 80;
          float y = 90;
          float z = 50;
          e.Graphics.DrawEllipse(Pens.Red, x - z, y - z, z * 2, z * 2);
        };
      }
      
      static void Main()
      {
        Application.Run(new Form1());
      }
    }
      

  2.   

    int x = 100;
                int y = 100;
                int z = 40;
                Graphics g = CreateGraphics();
                Pen pen = new Pen(Color.Red, 2);
                
                g.DrawEllipse(pen, x - z, y - z, 2 * z , 2* z);
                g.Flush();
                g.Dispose();
      

  3.   


     private void panel1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics;
                g.DrawEllipse( new Pen (Color.Yellow ,1 ) ,5,5,150,150);         
            }
    你看看吧!!
      

  4.   

    如果要画实心圆,则用 FillEllipse() 方法:using System;
    using System.Drawing;
    using System.Windows.Forms;class Form1 : Form
    {
      Form1()
      {
        Panel panel1  = new Panel();
        panel1.Parent = this;
        panel1.Dock   = DockStyle.Fill;
        panel1.Paint += delegate(object o, PaintEventArgs e)
        {
          // 画一个圆心为(x,y)半径为z的实心圆
          float x = 80;
          float y = 90;
          float z = 20;
          e.Graphics.FillEllipse(new SolidBrush(Color.Blue), x - z, y - z, z * 2, z * 2);
        };
      }
      
      static void Main()
      {
        Application.Run(new Form1());
      }
    }
      

  5.   

    在panel的Paint方法中,写上下面的代码...
            private int x = 100;
            private int y = 100;
            private int z = 50; 
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawEllipse(new Pen(Color.Green, 2), x - z, y - z, 2 * z, 2 * z);
                
                //下面部分可以省略,只是方便验证
                e.Graphics.DrawLine(new Pen(Color.Blue, 1), 0, 0, x, y);
                e.Graphics.DrawLine(new Pen(Color.Blue, 1), 0, y, x, y);
                e.Graphics.DrawLine(new Pen(Color.Blue, 1), x, 0, x, y);
            }
      

  6.   

    但是为什么刷新一下就没有啦?你是怎么刷新的,我这边很正常啊...
    OnPaint 是时时画的,别说你刷新,你就是切换界面它就会重新画一次.
      

  7.   

    GDI+画图一般是在内存中画,直接在窗体上画刷新就会没了。
    内存中画图方式:
    按钮单击事件中写一下代码
    Bitmap bmp = new Bitmap(400,500);
    Graphic g = Graphic.FromImage(bmp);
    g.DrawEllipse(...);   //参数省略
    然后呢在
    panel中放个图片控件
    pic.Image = bmp;
    差不多就这个意思
      

  8.   


    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
        {
            public Form1()
            {
                Panel panel1 = new Panel();
                panel1.Parent = this;
                panel1.Dock = DockStyle.Fill;
                //匿名方法
                panel1.Paint += delegate(object sender, PaintEventArgs e)
                {
                    // 画一个圆心为(x,y)半径为z的圆
                    float x = 80;
                    float y = 90;
                    float z = 50;
                    e.Graphics.DrawEllipse(Pens.Red, x - z, y - z, z * 2, z * 2);
                };
            }
        }
    }