Vb.net 带if语句的picutrebox
我正在使用VS2008和VB.NET Compact Framework 3.5开发一个项目。我有一个picturebox,可以从imagelist中加载图片。Imagelist中有3个图像,索引为0、1、2。是否有任何方法可以使用下面的if语句编写代码 加载表单时:Vb.net 带if语句的picutrebox,vb.net,if-statement,picturebox,Vb.net,If Statement,Picturebox,我正在使用VS2008和VB.NET Compact Framework 3.5开发一个项目。我有一个picturebox,可以从imagelist中加载图片。Imagelist中有3个图像,索引为0、1、2。是否有任何方法可以使用下面的if语句编写代码 加载表单时: picturebox.image = imagelist1.Images(0) 'give picture box an initial value ... If picturebox.image = imagelist1.
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,因此它永远不会运行“do something”
If picturebox.image Is imagelist1.Images(0) then
'do something
End If
提前感谢。更新picturebox时,请将当前索引存储在.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语句类似,输入更少,可读性更强。只是想知道为什么我的原始代码不起作用。即使返回False:MsgBox(ImageList1.Images(1)是ImageList1.Images(1))