Show form from thread

StewartBW 745 Reputation points
2024-06-09T15:10:06.14+00:00

Hello,

How can I call / invoke this code from inside thread?

Using F As New blahForm
F.Text = "xyz"
F.Tag = "abc"
F.ShowDialog(Me)
End Using

I think Invoke(Sub() ...) is single line command?

  • If InvokeRequired then...

Thanks :)

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,642 questions
{count} votes

Accepted answer
  1. Jack J Jun 24,491 Reputation points Microsoft Vendor
    2024-06-10T02:29:52.4933333+00:00

    @StewartBW , you could try the following code to invoke the code from the thread to show the form.

    BTW, you could use Form.StartPosition Property to locate the position of Form.

        Me.Invoke(
    Sub()
        Using F As New Form2
            F.Text = "xyz"
            F.Tag = "abc"
            F.StartPosition = FormStartPosition.CenterScreen
            F.ShowDialog()
        End Using
    End Sub)
    
    
    

    Best Regards,

    Jack


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful