鼠标单击时调用绘制事件

本文关键字:绘制 事件 调用 单击 鼠标 | 更新日期: 2023-09-27 18:09:39

 private void MainImage_Paint(object sender, PaintEventArgs e)
 {
     Point[] destinationPoints = {
                new Point(200, 20),   
                new Point(110, 100),  
                new Point(250, 30)};
     Bitmap image = new Bitmap(MainImage.Image);
     e.Graphics.DrawImage(image, 0, 0);
     e.Graphics.DrawImage(image, destinationPoints);
}

private void button7_Click(object sender, EventArgs e)
{
}

如何在鼠标点击时调用paint事件?在触发"on click"事件后,它应该在MainImage上绘制一个图像。

鼠标单击时调用绘制事件

使用this.Invalidate();this.Update();this.Refresh();

试试这个:

        Graphics.FromImage(MainImage);
        GraphicsUnit units = GraphicsUnit.Point;
        MainImage_Paint(MainImage,new PaintEventArgs ( Graphics.FromImage(MainImage),Rectangle.Round(MainImage.GetBounds(ref units)));