本帖最后由 hitomi427 于 2011-01-20 21:24:48 编辑

解决方案 »

  1.   

    picturebox的Paint()事件只有在picturebox1控件被其他窗体遮盖后,需要再次显示的时候,系统才会调用它
    调用pictureBox1.Refresh()是强行刷新
      

  2.   

    不应该使用Invalidate(),这样会把已经绘出的图形清除,应该这样:private void button1_Click(object sender, EventArgs e)
      {
    pictureBox.Refresh();
      }
      

  3.   

    那我应该怎么触发picture的paint事件呢
      

  4.   

    Invalidate可以用,作用是重新执行paint以更新失效区域,但后面不要再跟update了.试下去掉update,如果还是不行则先画到图上,再设置picturebox背景图
      

  5.   

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
      {
      Graphics g = e.Graphics ;  Pen pen=new Pen (Color .Blue,3);
      Point p=new Point (3,3);
      Point q = new Point(5, 5);
      g e.graphics.DrawLine(pen, p, q);
      }  private void button1_Click(object sender, EventArgs e)
      {
      this.pictureBox1.Invalidate();
      this.pictureBox1 .Update();  }
    }
      

  6.   


    先画到图上是什么意思呀?其实我也不一定要画到picturebox上,panel什么的都可以,只要不画到form上就好了
    再借地问一下,刚才用
    protected override void Onpaint(PaintEventArgs e)
    {
    ...
    }
    就能在窗体上画出来,这是为什么呢
      

  7.   


    ~~~~(>_<)~~~~ 还是不行,为什么要删掉Graphics g = e.Graphics 呢
      

  8.   

     int i=10, j=10;
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                           Graphics g = e.Graphics;
                Pen pen = new Pen(Color.Blue, 3);
                Point p = new Point(3, 3);
                Point q = new Point(i, j);
                g.DrawLine(pen, p, q);
            }        private void button1_Click(object sender, EventArgs e)
            {
                i = 20;
                j = 30;
                pictureBox1.Refresh();
            }可以变化
      

  9.   

    Using B as new bitmap(picturebox1.width,picturebox1.height)
    Using G as graphics=graphics.fromimage(B)
    dim P as point= new point(3,3)
    dim q as point=new point(5,5)
    dim pen as pen=new pen(color.blue,3)
    G.DrawLinde(pen,p,q)
    end using
    picturebox1.Image=B
    end using
      

  10.   

    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 WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
                 private void button1_Click(object sender, EventArgs e)
            {
                this.pictureBox1.Refresh();        }
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = e.Graphics ;
                Pen pen=new Pen (Color .Blue,3);
                Point p=new Point (3,3);
                Point q = new Point(5, 5);
                g .DrawLine(pen, p, q);
            }
                    
        }
    }这是我完整的程序了,大家能帮我看看么,点button什么也没有
    这个不通,后面的程序我都写不下去啊
    谢谢大家了
      

  11.   

    不会C#,以下是网页上翻译成C#的.写在button事件里,然后可以将paint里的代码全部删除.该代码作用是绘制到一张临时图上,并且将该图设置为picturebox的图片,所以不再需要paint了.
    using (bitmap B = new bitmap(picturebox1.width, picturebox1.height)) {
    using (graphics G = graphics.fromimage(B)) {
    point P = new point(3, 3);
    point q = new point(5, 5);
    pen pen = new pen(color.blue, 3);
    G.DrawLinde(pen, P, q);
    }
    picturebox1.Image = B;
    }
      

  12.   

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
      {
      Graphics g = e.Graphics ;
      Pen pen=new Pen (Color .Blue,3);
      Point p=new Point (3,3);
      Point q = new Point(5, 5);
      g.DrawLine(pen, p, q);
      }  private void button1_Click(object sender, EventArgs e)
      {
      this.pictureBox1.Refresh();
      }这个不应该有问题。