VB.net Invoke a property change in a control

橙三吉。 提交于 2019-12-11 00:38:50

问题


Lots of examples of how to invoke methods, but how does one change a simple property?

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

Thanks


回答1:


If you're using VB.Net 2010, you can use a lambda expression:

If myItem.InvokeRequired Then
    myItem.Invoke(Sub() myItem.Visible = True)

In your particular case, you can also call myItem.Invoke(myItem.Show).



来源:https://stackoverflow.com/questions/3869206/vb-net-invoke-a-property-change-in-a-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!