5 Replies - 9921 Views - Last Post: 21 October 2009 - 10:32 AM Rate Topic: -----

#1 agentjk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-February 07

How to code message box click event?

Post icon  Posted 20 October 2009 - 04:14 PM

I have a simple program. When the user clicks the beginbutton a warningmessagebox pops up. If OK is clicked I want another (different) message box to pop up. I'm assuming I need to code the warningmessagebox click event? How do I do that? I've only double clicked on the object in design view and thats not an option. Thanks!
Is This A Good Question/Topic? 0
  • +

Replies To: How to code message box click event?

#2 agentjk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-February 07

Re: How to code message box click event?

Posted 20 October 2009 - 04:57 PM

*Update

Ok, I have the 2nd message box popping up. This is my code thus far
Option Strict On

Public Class DeleteMainForm

	Private Sub BeginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginButton.Click
		Dim ResponseDialogResult As DialogResult

		ResponseDialogResult = MessageBox.Show("Do you want to delete file?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

		If ResponseDialogResult = DialogResult.OK Then
			MessageBox.Show("WARNING! It is dangerous to delete EXE file", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
		End If

	End Sub

	Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
		Me.Close()

	End Sub
End Class


Now I need to use a do/while loop to display the "WARNING!" messagebox 4 times. Can I use a do/while within an IF?
Was This Post Helpful? 0
  • +
  • -

#3 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: How to code message box click event?

Posted 20 October 2009 - 06:49 PM

You can repeat the If statement 3 more times or use a loop with a count down counter, however the multiple confirmations are BAD USER INTERFACE DESIGN. The users will count how many times and just keep hitting return without reading. Think about it - Windows provides the trash can that catches all deletions, so why should it ever ask me if I want to delete something when it is so easy to recover it? Answer is that it shouldn't, it should just move the file to the trash - even emptying the trash shouldn't require a confirmation as I had to do something special to even attempt that, not somehting accidental.
Was This Post Helpful? 0
  • +
  • -

#4 agentjk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-February 07

Re: How to code message box click event?

Posted 20 October 2009 - 06:55 PM

View Postmark.bottomley, on 20 Oct, 2009 - 05:49 PM, said:

You can repeat the If statement 3 more times or use a loop with a count down counter, however the multiple confirmations are BAD USER INTERFACE DESIGN. The users will count how many times and just keep hitting return without reading. Think about it - Windows provides the trash can that catches all deletions, so why should it ever ask me if I want to delete something when it is so easy to recover it? Answer is that it shouldn't, it should just move the file to the trash - even emptying the trash shouldn't require a confirmation as I had to do something special to even attempt that, not somehting accidental.

Thanks. I completely agree with you. However, this is homework and those are the directions. Below is what I came up with. I understand this code and it works but did I just get lucky? I'm new to loops.
Option Strict On

Public Class DeleteMainForm

	Private Sub BeginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginButton.Click
		Dim ResponseDialogResult As DialogResult
		Dim ResponseTwoDialogResult As DialogResult
		Dim ResponseInteger As Integer

		ResponseDialogResult = MessageBox.Show("Do you want to delete file?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

		Do While ResponseInteger <= 3
			If ResponseDialogResult = DialogResult.OK Then
				ResponseInteger += 1
				ResponseTwoDialogResult = MessageBox.Show("WARNING! It is dangerous to delete EXE file", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
			End If
		Loop

	End Sub


Was This Post Helpful? 0
  • +
  • -

#5 senoj  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 21-October 09

Re: How to code message box click event?

Posted 21 October 2009 - 01:18 AM

Hi first post here :)
If you change it so that your loop is inside your If statement then it is more effiecient because if ResponseDialogResult does not equal DialogResult.OK it will not go through the whole loop as it is doing now

If ResponseDialogResult = DialogResult.OK Then
		Do While ResponseInteger <= 3
			   ResponseInteger += 1
				ResponseTwoDialogResult = MessageBox.Show("WARNING! It is dangerous to delete EXE file", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
		Loop
End If 

Was This Post Helpful? 1
  • +
  • -

#6 agentjk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-February 07

Re: How to code message box click event?

Posted 21 October 2009 - 10:32 AM

View Postsenoj, on 21 Oct, 2009 - 12:18 AM, said:

Hi first post here :)
If you change it so that your loop is inside your If statement then it is more effiecient because if ResponseDialogResult does not equal DialogResult.OK it will not go through the whole loop as it is doing now

If ResponseDialogResult = DialogResult.OK Then
		Do While ResponseInteger <= 3
			   ResponseInteger += 1
				ResponseTwoDialogResult = MessageBox.Show("WARNING! It is dangerous to delete EXE file", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
		Loop
End If 


Thanks, it does make more sense that way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1