|
-
Oct 16th, 2009, 02:11 AM
#1
Thread Starter
Member
[RESOLVED] Custom MessageBox returns result
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.
-
Oct 16th, 2009, 03:35 AM
#2
Hyperactive Member
Re: Custom MessageBox returns result
You can use showDialog() instead of show(). ShowDialog() will pause the code until the form exits.
Runesmith
The key to getting the right answer is asking the right question
I just realized: good health is merely the slowest possible rate at which one can die
-
Oct 16th, 2009, 03:41 AM
#3
Thread Starter
Member
Re: Custom MessageBox returns result
ok. thank you.
But how will I return a result when a button is pressed??
-
Oct 16th, 2009, 03:47 AM
#4
Hyperactive Member
Re: Custom MessageBox returns result
Where do you declare these?
"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."
If result is declared at class level (outside any sub or function) it should be available to all your subs and functions. So, in your button_click procedures, simply assign a value to result. When the form is closed, code below showDialog() will start executing, and the value of result should still be available for you to return.
Runesmith
The key to getting the right answer is asking the right question
I just realized: good health is merely the slowest possible rate at which one can die
-
Oct 16th, 2009, 03:52 AM
#5
Thread Starter
Member
Re: Custom MessageBox returns result
Ahhhh. thank you very much.
Worked 100%
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|