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:
Now I want the message box to return a value:Code:CustomMessageBox.popUp()
But this should only return once the user clicks a button in the message box.Code:Dim a as Intger = CustomMessageBox.popUp()
My popUp sub:
gotResult is a Boolean = false. It the user clicks a button gotResult is changed to true.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
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:
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.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
The answer is maybe easy, but I can't think of anything.




Reply With Quote
