kta*_*rik 37 .net c# picturebox winforms
如何清除图片框上的绘图图像?以下对我没有帮助:
pictbox.Image = null;
pictbox.Invalidate();
Run Code Online (Sandbox Code Playgroud)
请帮忙.
编辑
private void pictbox_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
vl.Draw(g, ref tran.realListForInsert);
}
public void Draw(Graphics g, ref List<double> arr)
{
g.DrawRectangle(new Pen(Brushes.Red, 3), nodeArr[Convert.ToInt32(templstName)].pict.Location.X, nodeArr[Convert.ToInt32(templstName)].pict.Location.Y, 25, 25);
g.DrawRectangle(new Pen(Brushes.Green, 3), nodeArr[Convert.ToInt32(templstArgName)].pict.Location.X, nodeArr[Convert.ToInt32(templstArgName)].pict.Location.Y, 25, 25);
nodeArr[Convert.ToInt32(templstName)].text.Text = arr[Convert.ToInt32(templstArgName)].ToString();
arr[Convert.ToInt32(templstName)] = arr[Convert.ToInt32(templstArgName)];
}
Run Code Online (Sandbox Code Playgroud)
Fré*_*idi 35
正如其他人所说,设置Image财产null应该有效.
如果没有,则可能意味着您使用了InitialImage属性来显示图像.如果确实如此,请尝试将该属性设置为null:
pictBox.InitialImage = null;
Run Code Online (Sandbox Code Playgroud)
Cod*_*ray 29
将Image属性设置为null将正常工作.它将清除图片框中当前显示的任何图像.确保您已完全按照以下方式编写代码:
picBox.Image = null;
Run Code Online (Sandbox Code Playgroud)
小智 9
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
pictureBox1.Image = null;
}
Run Code Online (Sandbox Code Playgroud)
我假设您想清除通过PictureBox绘制的图像。
这可以通过使用Bitmap对象并使用Graphics对象来实现。你可能正在做类似的事情
Graphics graphic = Graphics.FromImage(pictbox.Image);
graphic.Clear(Color.Red) //Color to fill the background and reset the box
Run Code Online (Sandbox Code Playgroud)
这就是您要寻找的东西吗?
编辑
由于您使用的是paint方法,因此每次都会重新绘制它,因此建议您在窗体级别设置一个标志,指示是否应绘制Picturebox
private bool _shouldDraw = true;
public bool ShouldDraw
{
get { return _shouldDraw; }
set { _shouldDraw = value; }
}
Run Code Online (Sandbox Code Playgroud)
在您的油漆中使用
if(ShouldDraw)
//do your stuff
Run Code Online (Sandbox Code Playgroud)
当您单击按钮时,将此属性设置为false即可。
小智 5
private void ClearBtn_Click(object sender, EventArgs e)
{
Studentpicture.Image = null;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
160841 次 |
| 最近记录: |