更新时间:2023-02-02 17:23:44
Try moving the drawing logic to the Paint
evet.
让我们假设您正在一个名为pnl
的面板上绘画.请尝试以下操作:
Let's assume you are drawing on a panel called pnl
. Try the following:
在构造函数上注册到绘画绘画专家:
On your constructor register to the paint evet:
this.pnl.Paint += pnl_Paint;
在单击时,设置一个标志以指示矩形需要绘画:
Upon a click, set a flag to indicate that painting is required for the rectangle:
bool _paintRect;
private void button1_Click(object sender, EventArgs e)
{
this._paintRect = true;
Invalidate();
Refresh();
}
在paint事件处理程序中,进行实际的绘制:
In the paint event handler, do the actual paint:
private void pnl_Paint(object sender, PaintEventArgs e)
{
//take screenshot of transparent form area
Bitmap CapturedScreen = ScreenShot.Create((this.Left + 8), (this.Top + 30), 780, 415);
ImageData refpic = new ImageData("pallo.bmp");
ImageData source = new ImageData(CapturedScreen);
Graphics graphics = e.Graphics;
Pen p = new Pen(Color.Black, 1);
graphics.DrawRectangle(p, Template.Image(source, refpic, 100));
}