VB.net调用控件中的属性更改 [英] VB.net Invoke a property change in a control
本文介绍了VB.net调用控件中的属性更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
很多关于如何调用方法的示例,但是如何改变一个简单的属性呢?
Lots of examples of how to invoke methods, but how does one change a simple property?
为演示起见,这是一组非常简单的代码,应该会有所帮助.假设我需要从子表单中设置visible属性,因此需要调用它:
For demonstration-sake, here's a very simple set of code that should help. Let's say I need to set the visible property from a child form, and thus, it needs to be invoked:
Friend Sub activateItem(ByVal myItem As PictureBox)
If myItem.InvokeRequired = True Then
????
Else
myItem.Visible = True
End If
End Sub
谢谢
推荐答案
如果使用的是VB.Net 2010,则可以使用lambda表达式:
If you're using VB.Net 2010, you can use a lambda expression:
If myItem.InvokeRequired Then
myItem.Invoke(Sub() myItem.Visible = True)
在特定情况下,您也可以致电myItem.Invoke(myItem.Show)
.
In your particular case, you can also call myItem.Invoke(myItem.Show)
.
这篇关于VB.net调用控件中的属性更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文