Brad
Brad

Reputation: 1369

VB.net Invoke a property change in a control

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

Upvotes: 2

Views: 8248

Answers (1)

SLaks
SLaks

Reputation: 887355

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).

Upvotes: 7

Related Questions