如何通过代码操作按钮的imagelist属性,以更改按钮图像 [英] how do i manipulate the imagelist property of button through code,to change button image

查看:91
本文介绍了如何通过代码操作按钮的imagelist属性,以更改按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过添加图像列表中的不同图像来更改按钮的颜色



Button1.Image = ImageList1.Images [1]



''获取类型system.windows.form.imagelist1.imagecollection的错误值无法在system.drawing.image中转换



i需要按钮颜色(图像)在满足某个条件后应该更改

how do i change the color of the button by adding a different image from image list

Button1.Image=ImageList1.Images[1]

''getting error value of type system.windows.form.imagelist1.imagecollection can not be converted in system.drawing.image

i need the button color(image) should change after a certain condition is met

推荐答案

如果我想要那个功能,我根本不会这样做。我会使用工具条而不是按钮。您可以将它们浮动到表单上的任何位置,并使它们透明。您可以设置多个按钮,并使用要删除的图像隐藏按钮,并显示包含您要显示的按钮的按钮。这使得为​​不同按钮状态添加功能更加容易,因为它们每个都有自己的事件处理程序。我在我的CodeProject文章中做到了这一点:

SharpZipLib或DotNetZip ...你应该使用哪种?

为什么不下载项目并看看?我想你会更喜欢这样做,然后使用标准按钮。我自己再也不用了。
I wouldn''t do that at all if I wanted that functionality. I would use a toolstrip instead of a button. You can float them anywhere on your form, and make them transparent. You can set up a number of buttons, and hide the button with the image you want to remove, and show the button with the one you want to show. This makes adding functionality for the different button states easier, as they each have their own event handler. I did this in my CodeProject article:

SharpZipLib or DotNetZip... Which should you use?

Why not download the project and have a look? I think you''ll be happier doing it this way then using a standard button. I never use them anymore myself.


这篇关于如何通过代码操作按钮的imagelist属性,以更改按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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