从按钮清除图像 [英] Clearing image from button

查看:77
本文介绍了从按钮清除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过编程将图像分配给按钮很好

I assign an image to a button programmatically which is fine

Stream imgStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Call_Manager.Resources.Tick.gif");
btnCancel.Image = Bitmap.FromStream(imgStream) as Bitmap;
btnCancel.ImageAlign = ContentAlignment.MiddleRight;



但我无法清除图像.我已经尝试了以下所有方法,但是都没有运气.我做错了什么?



but I am unable to clear the image. I have tried all the following but with no luck. What am I doing wrong?

btnCancel.Image = null;
btnCancel.Image.Invoke();

推荐答案


btnCancel.Image.Invoke();



甚至可以编译吗?

没关系.

试试



even compile?

Never mind.

Try

btnCancel.Image.Dispose()
btnCancel.Image = null;
btnCancel.Invalidate();  // OR btnCancel.Refresh();


Stream imgStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Call_Manager.Resources.Tick.gif");
btnCancel.Image = Bitmap.FromStream(imgStream) as Bitmap;
imgStream.Close(); //Close stream
btnCancel.ImageAlign = ContentAlignment.MiddleRight;

btnCancel.Dispose(); //Dispose image to free all it's resources
btnCancel.Image = null;
btnCancel.Invalidate(); //Causes repaint of control
btnCancel.Image.Invoke();




干杯,


曼弗雷德(Manfred)




Cheers,


Manfred


这篇关于从按钮清除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆