window handles

rbreidenstein

Member
Joined
Dec 4, 2005
Messages
21
Programming Experience
1-3
I am attempting to invoke a sub through a delegate from a seperate class. When i try to run the code is says that a window handle needs to be created.

Can someone point me in the right direction?


Invoke(New form1.Delegate(AddressOf Form1.DeltaProperty), _
form1.AssetProgressBar1, "Step", "1", "State")
 
Is Form1 the name of a class or is it the name of a variable that refers to a form instance? Also, are you calling this from a form? Invoke is a member of the Control class so it must be called on an instance of a class that inherits Control.
 
form1 is my form with the gui, then i have another class which has a sub that is started in a thread when a button is clicked on the from. from this sub in seperate class (not in the form) i need to call back to the gui thread to update a progressbar or change text in a lable or textbox.
 
If you are calling Invoke form a class that doesn't inherit Control then you cannot call Invoke unqualified. It is a member of the Control class and thus must be called on a control. If you are trying to access an existing instance of a for then you must have a reference to that instance, which I assume form1 is. In that case, you should be calling form1.Invoke. Also, Invoke only takes two arguments. You have to create a Object array to pass the arguments you want passed to the method you specify:
VB.NET:
form1.Invoke(New form1.Delegate(AddressOf form1.DeltaProperty), New Object() {form1.AssetProgressBar1, "Step", "1", "State"})
There is also something else going on because your code is trying to create an instance of a delegate named "Delegate", but you couldn't possibly have defined a delegate with that name because the compiler wouldn't let you use a keyword like that. If you want to invoke a method using a delegate then you have to define a delegate that matches its signature:
VB.NET:
    Public Delegate Sub DeltaPropertyDelegate(ByVal ctl As Control, ByVal str1 As String, ByVal str2 As String, ByVal str3 As String)

    Public Sub DeltaProperty(ByVal ctl As Control, ByVal str1 As String, ByVal str2 As String, ByVal str3 As String)

    End Sub
 
Back
Top