|
-
Nov 21st, 2003, 11:04 AM
#1
Thread Starter
Addicted Member
What to do when user click msgbox button
Will anyone help me on how to catch a button when a user click on a msgbox()? Let's say I have this:
Code:
msgbox("You've entered the wrong password", MsgBoxStyle.Critical)
Now when the user click the "OK" button on that msgbox(), I want to catch that and do something else with it.
Any help is appreciated.
ljCharlie
-
Nov 21st, 2003, 11:18 AM
#2
Lively Member
For example (cut from an app I work on):
VB Code:
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
Select Case MsgBox("This character has changed since it was last saved. Do you want to save changes before exiting?", _
MsgBoxStyle.YesNoCancel, "Warning")
Case MsgBoxResult.Yes
'Save first
If Globals.strCharFileName = "" Then
If Me.dlgSave.ShowDialog = DialogResult.OK Then
Globals.SaveCharacter(Me.dlgSave.FileName)
End If
Else
Globals.SaveCharacter(strCharFileName)
End If
Me.Close()
Case MsgBoxResult.No
'Quit without saving
Globals.Dirty = False
Me.Close()
Case MsgBoxResult.Cancel
'Aborting
e.Cancel = True
End Select
End Sub
...although it has been pointed out that the .NET function is MessageBox.Show, you (and I also!) shouldn't be using msgbox any more. It works the same way though.
-
Nov 21st, 2003, 11:19 AM
#3
like this...
VB Code:
If MessageBox.Show("You've entered the wrong password", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error) = DialogResult.OK Then
'/// do stuff because OK was clicked
End If
or with the old vb6 method of MsgBox ...
VB Code:
If MsgBox("You've entered the wrong password", MsgBoxStyle.OKOnly) = MsgBoxResult.OK Then
'/// do stuff
End If
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Nov 21st, 2003, 11:23 AM
#4
Thread Starter
Addicted Member
Thank you very much! I didn't know that VB.NET change msgbox() to Message.Show(). And crucial point I missed is the DialogResult.OK or MsgBoxResult.OK.
Well, I'll give that try. I'm very sure it will work.
Again, thank you.
ljCharlie
-
Nov 21st, 2003, 11:30 AM
#5
Lively Member
All DialogResult is is a built in enumeration of the different messagebox returns, you could just as easily use the number represented by each messagebox button (although I don't know what they are since I use DialogResult).
Public Enum MsgBoxResult As Integer
Member of: Microsoft.VisualBasic
Summary:
The MsgBoxResult enumeration contains constants used to identify which button was pressed on a message box displayed using the MsgBox function. These constants can be used anywhere in your code.
-
Nov 21st, 2003, 11:33 AM
#6
Thread Starter
Addicted Member
Yes, I remember using numbers in VB6 during my college years. However, it's quite hard to remember those numbers though. Well, it worked out okay now.
ljCharlie
-
Nov 21st, 2003, 11:41 AM
#7
Thread Starter
Addicted Member
By the way, is there an equivalent event for the .lostfocus in VB.NET? I thouht there is the .Leave but it wasn't working. Here's my situation.
In the txtUserName textbox, I set a KeyUp event to capture the Enter key. If the user hit the enter key, then move the focus to the txtPassword textbox. And in the txtPassword textbox I also setup a KeyUp event to catch the Enter key. If in the txtPassword the user hit the Enter key, then performclick on the btnOK button. Now the problem is, if the user type in the wrong password and the error messagbox popup and the user hit the Enter key again, the error messagebox kept on poping up. That is because the focus is still on the txtPassword textbox. So my question is, is there a way to lose the focus on that txtPassword textbox?
ljCharlie
-
Nov 21st, 2003, 01:08 PM
#8
Frenzied Member
That would be a very good reason NOT to use the enter key to move to the next field...use tab.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Nov 21st, 2003, 01:10 PM
#9
Thread Starter
Addicted Member
Thanks for the response, but almost 99% people don't use the Tab key. Normally people would use the Enter key. So I'm stock.
ljCharlie
-
Nov 21st, 2003, 03:57 PM
#10
I wonder how many charact
Easy way:
Check for Enter in the passwordBox keypress event, and call your error message box there if they fail. There's no reason to check it in the Leave event is there?
Just to give you a more complex solution:
In our production enterprise application, the login form returns a userNominee. This is a user that is attempting authentication. The calling nominee is returned back to a class subroutine that actually called the login form.
If the user failed authentification, and has not attempted more than 3 times on this running instance, we create another login form, and they can try again.
Perhaps you could go that route.
-
Nov 21st, 2003, 04:01 PM
#11
Thread Starter
Addicted Member
I see what you're saying now. I'll give that a try and see what happens. Thanks!
ljCharlie
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
|