0

ピクチャボックスのボタンがクリックされたときに作成される長方形のグラフィックオブジェクトを持っていますが、フォームが画面外に移動するとグラフィックが消え、フォーム全体が白くなるだけですピクチャボックスを無効にしようとしましたしかし、これによりボタンが機能しなくなります無効化メソッドを使用してオブジェクトをフォームに保持するのを手伝ってくれる人はいますか?方法があることは知っていますが、それを把握できないようです

  private void squareButton_Click(object sender, EventArgs e)
        {

            // Declaring a new graphics object has been assigned null
            Graphics objGraphics = null;
            // This will create the picture graphics to be drawn in the picturebox
            objGraphics = PictureBox1.CreateGraphics();
            // This will redraw the picture box with a fill chosen after the systemcolors
            objGraphics.Clear(SystemColors.ControlDark);
            // This will draw the rectangle with a red pen 10,10 represent position and 50,50 reprsent the width and height 
            objGraphics.DrawRectangle(Pens.Red, 10, 10, 50, 50);
            // This will draw the rectangle
            objGraphics.Dispose();
invalidate(PictureBox1);

// This is not redrawing the graphic it just shows a blank form

        }
4

1 に答える 1

0

Try this:

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    Graphics objGraphics = null;
    // This will create the picture graphics to be drawn in the picturebox
    objGraphics = e.Graphics;
    // This will redraw the picture box with a fill chosen after the systemcolors
    objGraphics.Clear(SystemColors.ControlDark);
    // This will draw the rectangle with a red pen 10,10 represent position and 50,50 reprsent the width and height 
    objGraphics.DrawRectangle(Pens.Red, 10, 10, 50, 50);
    // This will draw the rectangle
    //objGrphics.Dispose();

}
于 2013-10-16T18:50:51.393 に答える