C# 在c语言中重画时,如何在面板中保留现有图像?
我有一个面板,我在那里画的按钮点击图像。但在第二次单击按钮时,先前绘制的图像将被新图像替换C# 在c语言中重画时,如何在面板中保留现有图像?,c#,image,panel,draw,C#,Image,Panel,Draw,我有一个面板,我在那里画的按钮点击图像。但在第二次单击按钮时,先前绘制的图像将被新图像替换 void panel_Image_Paint(object sender, PaintEventArgs e) { if (Clipboard.ContainsImage()) { Point p1 = new Point(i, 0); e.Graphics.DrawImage(Clipboard.GetImage(), p1); i += img.Width; } } 在
void panel_Image_Paint(object sender, PaintEventArgs e)
{
if (Clipboard.ContainsImage())
{
Point p1 = new Point(i, 0);
e.Graphics.DrawImage(Clipboard.GetImage(), p1);
i += img.Width;
}
}
在绘制新图像时,我希望在面板中保留先前绘制的图像。剪贴板将在每次单击按钮时使用新图像刷新。任何帮助都将不胜感激!!!!
谢谢 我不确定绘制事件实际上是如何工作的,以及是什么原因导致图像消失,但您可以尝试将图像添加到列表中,然后在列表中循环以在面板上显示所有图像。 请尝试以下代码:
int i = 0;
List<Image> Images = new List<Image>();
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (Clipboard.ContainsImage())
{
Images.Add(Clipboard.GetImage());
foreach (Image item in Images)
{
e.Graphics.DrawImage(item, new Point(i,0));
i += Clipboard.GetImage().Width;
}
}
i = 0;
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Invalidate();
}