I've created a custom MessageBox (a Form), that has buttons Yes and No.
There is a function popUp() to show the MessageBox.

I would call the MsgBox in a parent as follows:
Code:
CustomMessageBox.popUp()
Now I want the message box to return a value:
Code:
Dim a as Intger = CustomMessageBox.popUp()
But this should only return once the user clicks a button in the message box.

My popUp sub:


Code:
    Dim thread As New Threading.Thread(AddressOf GetResult)

    Public Function PopUp(Optional ByVal ErrorMessage As String = "", Optional ByVal Title As String = "", Optional ByVal ButtonType As ButtonType = ButtonType.OK, Optional ByVal MessageType As MessageType = MessageType.None)
        'The following 5 lines do the GUI stuff and shows the box.
        AddMessageText(ErrorMessage)
        AddTitle(Title)
        AddButtons(ButtonType)
        AddIcon(MessageType)
        Show()
        thread.Start()
        Return result
    End Function

    Private Sub GetResult()
        While (Not gotResult)
        End While
    End Sub
gotResult is a Boolean = false. It the user clicks a button gotResult is changed to true.
result is a integer containing the number of the button clicked.

When I run this code, the result is returned, even if the user doesn't click a button. I understand why, because the main thread of the form is not "paused" while the user has not clicked a button.

How can I pause the message box itself, untill a button was clicked?
I've tried this:
Code:
    Public Function PopUp(Optional ByVal ErrorMessage As String = "", Optional ByVal Title As String = "", Optional ByVal ButtonType As ButtonType = ButtonType.OK, Optional ByVal MessageType As MessageType = MessageType.None)
        'The following 5 lines do the GUI stuff and shows the box.
        AddMessageText(ErrorMessage)
        AddTitle(Title)
        AddButtons(ButtonType)
        AddIcon(MessageType)
        Show()
        While (Not gotResult)
        End While
        Return result
    End Function
But now the hole message box is caputered in a loop and the message box is like disabled, because it waits for the loop to end, so the user can't click anything.

The answer is maybe easy, but I can't think of anything.