Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I just cannot understand why it is not working?

It seems everything is alright:

   Delegate Sub SetFocusCallback(ByVal Focus As Boolean)
   Private Sub SetFocus(ByVal Focus As Boolean)
       If Me.OKButton.InvokeRequired Then
           Dim d As New SetFocusCallback(AddressOf SetFocus)
           Me.Invoke(d, New Object() {Focus})
       Else
           Me.OKButton.Focus = Focus
       End If
   End Sub
...
Me.SetFocus(True)
...

Also in this line:

Me.OKButton.Focus = Focus

I get this error:

Error 1 Expression is a value and therefore cannot be the target of an assignment.

Posted

So you mean I should change my code to something like this:

   Delegate Sub SetFocusCallback()
   Private Sub SetFocus()
       If Me.OKButton.InvokeRequired Then
           Dim d As New SetFocusCallback(AddressOf SetFocus)
           Me.Invoke(d, New Object() {Focus})
       Else
           Me.OKButton.Focus()
       End If
   End Sub
...
usage
...
Me.SetFocus()

I just am not sure if this section:

       If Me.OKButton.InvokeRequired Then
           Dim d As New SetFocusCallback(AddressOf SetFocus)
           Me.Invoke(d, New Object() {Focus})
       Else

is correct?

  • Leaders
Posted

What is "Focus" in the line:

 

Me.Invoke(d, New Object() {Focus})

 

If it is not a declared variable then it will refer to the form's focus method, in which case you may be inadvertently invoking it, which you would be doing across threads, hence your error.

[sIGPIC]e[/sIGPIC]
Posted

Me.Invoke(d)

 

Me.Invoke(d)

 

That is correct (since the delegate takes no arguments). Good luck :cool:

Never trouble another for what you can do for yourself.
Posted

Hi all,

I just have one more last question:

       If SaveCheckBox.Checked = True Then SaveButton.Enabled = True

I just wanna check if my check box on form is checked then enable a button in my safe thread.

But could not implement this.

Can someone help me? :)

Posted

   Delegate Sub SetFocusCallback()
   Private Sub SetFocus()
       If Me.SaveCheckBox.InvokeRequired Then
           Dim d As New SetFocusCallback(AddressOf Enabled)
           Me.Invoke(d, New Object() {Enabled})
       Else
           If Me.SaveCheckBox.Enabled = True Then SaveButton.Enabled = True
       End If
   End Sub

It won't work! :(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...