我这样怎么不显示图出来?
public Form1()
        {
            InitializeComponent();
            Pen pen = new Pen(Color.Red);
            pen.Width = 5;
            //Graphics gr = this.CreateGraphics();
            this.CreateGraphics().DrawEllipse(new Pen(Color.Red), 125 - 5, 130 - 5, 2 * 5, 2 * 5);
        }

解决方案 »

  1.   


    下面两种方法可以任选一种试试看
    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()
            {
                InitializeComponent();
                
                //方法1
                Bitmap img = new Bitmap(this.Width, this.Height);
                Graphics g = Graphics.FromImage(img);
                Pen pen = new Pen(Color.Red);
                pen.Width = 5;            
                g.DrawEllipse(new Pen(Color.Red), 125 - 5, 130 - 5, 2 * 5, 2 * 5);
                this.BackgroundImage = img;
            }        private void Form1_Paint(object sender, PaintEventArgs e)
            {
                //方法2
                Pen pen = new Pen(Color.Red);
                pen.Width = 5;
                //Graphics gr = this.CreateGraphics(); 
                this.CreateGraphics().DrawEllipse(new Pen(Color.Red), 125 - 5, 130 - 5, 2 * 5, 2 * 5);         }
        }
    }
      

  2.   

    下面的只有按钮可以画出来!·
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace DeviceApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                aa();
            }        private void button1_Click(object sender, EventArgs e)
            {
                aa();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                aa();
            }
            void aa() {
                Pen pen = new Pen(Color.Red);
                pen.Width = 5;
                //Graphics gr = this.CreateGraphics();
                this.CreateGraphics().DrawEllipse(new Pen(Color.Red), 125 - 5, 130 - 5, 2 * 5, 2 * 5);
            }
        }
    }
      

  3.   

    呵呵 方法1不错~~画BITMAP里~~ 然后显示到背景~~学习了:)
      

  4.   

        private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Pen pen = new Pen(Color.Red);
                pen.Width = 5;
                //Graphics gr = this.CreateGraphics(); 
                this.CreateGraphics().DrawEllipse(new Pen(Color.Red), 125 - 5, 130 - 5, 2 * 5, 2 * 5);         }