繁体   English   中英

带有if语句的picutrebox

[英]picutrebox with if statement

我正在使用VS2008与VB.NET Compact Framework 3.5来开发一个项目。 我有一个图片框,可以从图像列表中加载图片。 Imagelist中有3个图像,索引为0,1,2。有没有办法用if语句编写代码,如下所示?

表单加载时:

picturebox.image =  imagelist1.Images(0) 'give picture box an initial value

...

If picturebox.image = imagelist1.Images(0) then
    'do something
elseif picturebox.image = imagelist1.Images(1) then
    'do something
elseif picturebox.image = imagelist1.Images(2) then
    'do something
End If

我也尝试使用Is而不是“=”,如下所示,但仍然无法正常工作。 在debug中,语句返回false,因此它永远不会运行'做某事。

If picturebox.image Is imagelist1.Images(0) then
    'do something
End If

提前致谢。

更新图片框时,将当前索引存储在.Tag属性中,以便对其进行评估:

picturebox.image =  imagelist1.Images(0) 
picturebox.Tag = 0

后来:

Select Case picturebox.Tag
    case 0             ' same as If picturebox.Tag = 0 then
      'do something
    Case 1
      'do something 1
    Case 2
      'do something 2
End Select

注意:case语句类似于If语句,键入次数少,可读性更高。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM