Form_Load画图前加上一行
this.Show();(2)(3)建议你把图片画在BitMap里面,然后绑定给Form.Image属性

解决方案 »

  1.   


    我没用过BitMap,它是一种图片格式吗?是不是将画好的图保存为一张bitmap格式的图片,然后每次刷新都是显示这张图片吗?
    还有我现在的代码写了很多
      

  2.   

    http://bbs.csdn.net/topics/3908835495#https://code.csdn.net/snippets/474628
      

  3.   

    在PictureBox控件的Paint事件里画就可以了
      

  4.   


    还是不能,但当最大化之后如果按键控件捕捉到鼠标移动事件的时候就会触发重绘,如果没有捕捉到一直空白OnLoad的时候还不会显示窗体,你如何判断是否空白?
      

  5.   

    还是不能,但当最大化之后如果按键控件捕捉到鼠标移动事件的时候就会触发重绘,如果没有捕捉到一直空白
    OnLoad的时候还不会显示窗体,你如何判断是否空白?我在OnPaint里面有 DrawLine的语句,当我最按下最大化后,没有在picturebox看到画出相英的图形,当我将鼠标移到按键的控件上时(没有按下),它就画出了(也就是在picturebox看到相应图形)。
      

  6.   

    不要自己创建一个绘图对象。
    试试下面的,测试没问题    class Form3:Form
        {
            public Form3()
            {
                this.SetStyle(ControlStyles.ResizeRedraw, true);
            }        protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                e.Graphics.DrawLine(Pens.Black, new Point(0, 0), new Point(Width, Height));
            }
        }
      

  7.   

    以上说的所有在form1上作图是有效在
    但在picturebox作图就无效了 g = this.CreateGraphics();//有效g = pictureBox1.CreateGraphics();//无效
      

  8.   

    写一个重绘的方法,然后在OnPaint事件里调用这个方法
      

  9.   

    绘图不要用CreateGraphics()
    MSDN上说的很清楚,不知道哪个培训机构乱教。控件的绘图用OnPaint或者Paint事件中的Graphics
      

  10.   


    1,我自己上网学的,没办法,没人教,公司又舍不得请人,
    2,我要一个全局的变量 如 g = pictureBox1.CreateGraphics()这样我就可以有外部的一个类中调用它来作图,而OnPaint的Graphics我在外部怎么用呢?
    3,有什么方法比较简单地补救?
      

  11.   

    多去MSDN上看看。控件的刷新界面用Invalidate() Refresh(),自动会调用OnPaint,并触发Paint事件的
      

  12.   

    class MyPictureBox:PictureBox
        {
            public MyPictureBox()
            {
                this.SetStyle(ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);  
            }
            public Rectangle Rect { get; set; }
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                Graphics g = e.Graphics;
                Pen p = new Pen(Color.Red,1);
                g.DrawRectangle(p,Rect);
                p.Dispose();
            }
        }
    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                MyPictureBox myPic = new MyPictureBox();
                myPic.Size = new Size(300,200);
                myPic.Location = new Point(10,10);
                myPic.BorderStyle = BorderStyle.FixedSingle;
                this.Controls.Add(myPic);
                myPic.Rect = new Rectangle(5,5,100,100);
                myPic.Invalidate();
            }
        }