如何从资源加载一系列图片? [英] How do I load series of pictures from resource?

查看:128
本文介绍了如何从资源加载一系列图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b请注意以下代码:



Hi Please kindly pay attention to below code:

Me.btn1.Image = My.Resources.PicOfBTN01
Me.btn2.Image = My.Resources.PicOfBTN02
Me.btn3.Image = My.Resources.PicOfBTN03
 .
 .
 .
Me.btn30.Image = My.Resources.PicOfBTN30





我需要知道,我怎么能做这个工作,用FOR?

因为我不想输入30次线:(



谢谢。



I need to know, how can I do this job, with a FOR ?
Because I don't want to type a line for 30 times :(

Thanks.

推荐答案

键入30行可能更容易...



获取资源本身并不算太糟糕:

It's probably easier to type the 30 lines...

Getting the resource itself isn't too bad:
Dim obj As Bitmap = My.Resources.ResourceManager.GetObject("MyPic2")
PictureBox1.Image = obj



会这样做(尽管你可能想要将图像缓存在一个数组中,如果你经常使用它们每次都有一个新图像 - 所以你所要做的就是在循环中生成资源名称picOfBtn+整数值。



但是......那么你必须循环所有的控制ols,确定要为其设置图像的按钮,获取其名称(Easy:Name属性将执行此操作),将名称缩小以获取整数,构建属性名称字符串然后您可以使用ResourceManager得到图像。



看看我的意思?自己做线路的速度更快......


Will do it (though you would probably want to cache the images in an array if you use them often as it returns a new image each time) - so all you have to do is generate the resource name "picOfBtn" + integer value in the loop.

But...then you have to loop through all the controls, identify the buttons you want to set an image for, get its name (Easy: the "Name" property will do that), break the name down to get the integer, build the property name string and then you can use the ResourceManager to get the image.

See what I mean? It's faster to do the lines yourself...


这篇关于如何从资源加载一系列图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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