试了一下,可以在form上画出来,可是在PictureBox里面的图像上就画不出来!

解决方案 »

  1.   

     protected override void OnPaint(PaintEventArgs e)
            {
                
                    e.Graphics.DrawRectangle(Pens.Red, 500 / 2, 500 / 2, 100, 100);
                    e.Dispose();
                
               
            }
      

  2.   

    自定义控件  继承自PictureBox在控件内重写OnPaint方法
      

  3.   

    画出来的矩形会被picturebox里面的图像挡住是怎么回事呢?
      

  4.   

    picturebox的Paint事件中
    private   Rectangle   m_Rect; 
    m_Rect   =   new   Rectangle(10,   10,   100,   80); 
    private   void   panel1_Paint(object   sender,   PaintEventArgs   e) 

    e.Graphics.DrawRectangle(SystemPens.HotTrack,   this.m_Rect); 

      

  5.   

    如1楼重写OnPaint方法,但是在绘制之前加上 base.OnPaint();
      

  6.   

    using G as graphics=graphics.fromimage(picturebox1.backgroundimage)
    ...
    end using
      

  7.   


       Graphics g = this.pictureBox1.CreateGraphics();
       g.DrawRectangle(new Pen(new SolidBrush(Color.Red)), 10, 10, 60, 30);