Point mypoint=new Point();
 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
 { 
     if (e.Button == MouseButtons.Left)
            {
               mypoint.X = e.X;
                mypoint.Y = e.Y;
            }
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
              Graphics g = this.CreateGraphics();
                SolidBrush sb = new SolidBrush(Color.Black);
                Pen mypen = new Pen(sb, 2f);
               g.DrawEllipse(mypen, mypoint.X - 1, mypoint.Y - 1, 20, 20);
 
        }
为什么picturebox没有什么反应呢 

解决方案 »

  1.   

    Paint修改一下
    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        SolidBrush sb = new SolidBrush(Color.Black);
        Pen mypen = new Pen(sb, 2f);
        g.DrawEllipse(mypen, mypoint.X - 1, mypoint.Y - 1, 20, 20);
        mypen.Dispose();
        sb.Dispose();
    }
      

  2.   

    问题是我想在picturebox上点一下,就在那画一点。
      

  3.   

    再添加一句
    Point mypoint=new Point();
    bool isok;
     private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
     {  
      if (e.Button == MouseButtons.Left)
      {
       isok=true;  
       mypoint.X = e.X;
       mypoint.Y = e.Y;
      }
    }
    private void pictureBox1_Paint(object sender, PaintEventArgs e)
      {
         if(isok==true)  
         {
             Graphics g = this.CreateGraphics();
             SolidBrush sb = new SolidBrush(Color.Black);
             Pen mypen = new Pen(sb, 2f);
             g.DrawEllipse(mypen, mypoint.X - 1, mypoint.Y - 1, 20, 20);
          
      
      }
    但是picturebox没有什么反应呢 
      

  4.   

    2楼已经给过你答案了。this.CreateGraphics();
    这是创建窗体的Graphics对象。你需要往PictureBox上绘制,你可以使用Paint的参数e.Graphics
    或是创建一个,但创建需要写
    Graphics g = PictureBox1.CreateGraphics();
      

  5.   


    你不行的代码贴来
    pictureBox1_Paint
    把你的这个事件代码换成2楼给你的不行?
      

  6.   

    在你mouse_down中写一句picturebox1.invalidrate().
    二楼贴的就能画出了,但需要你切换一下窗体。你按刚说的修改就立刻能看到改变。
      

  7.   

    MouseDown 事件中添加一句强制刷新试试
    this._picBox.Refrush();  //好像是这个函数,不记得了
      

  8.   

    其实楼主已经画出了一个点,只是这个点在pictureBox1的背后,看不到而已。
    楼主的代码下再加一句
            Point mypoint = new Point();
            private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    mypoint.X = e.X;
                    mypoint.Y = e.Y;
                    pictureBox1.Invalidate();
                }
            }