Suppose we are coding a messagebox on closing event of a form.
It Shows three buttons Yes,No and Cancel. Now I wish to code for CANCEL button.
How can I achieve this ?
I'm not exactly sure how to do this off the top of my head. have you seen if the message box returns a dialog result. I know alot of of .net dialogs have a dialog result. if you designed the message box yourself you can go to the properties of the cancel button and select the dialog result to be :
An example by Darin Dimitrov on StackOverflow:
Dim result = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel) If result = DialogResult.Cancel Then MessageBox.Show("Cancel pressed") ElseIf result = DialogResult.No Then MessageBox.Show("No pressed") ElseIf result = DialogResult.Yes Then MessageBox.Show("Yes pressed") End If
Hope this helps
Edited 3 Years Ago by lolafuertes
Something like this
Dim diares As Windows.Forms.DialogResult = MsgBox("Test", MsgBoxStyle.YesNoCancel) If diares = Windows.Forms.DialogResult.Yes Then MsgBox("Yes pressed") ElseIf diares = Windows.Forms.DialogResult.No Then MsgBox("No pressed") ElseIf diares = Windows.Forms.DialogResult.Cancel Then MsgBox("Cancel pressed") End If
Thank You Fellas for your contribution.
I have fortunatley figured it out how to achieve that functionality and I am encliosing following code for you all to refer in future.
Private Sub frmQuestion_Paper_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing Dim msg As DialogResult = MessageBox.Show("Do you want to save the changes made to Question Paper?", "Warning !! ", _ MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) If msg = DialogResult.Cancel Then MessageBox.Show("Sorry !! ") e.Cancel = True End If End Sub
As you can see e.Cancel= True cancel the calling of FormClosing Event and hence Form is saturated in it's current state.
Glad to hear.
Please mark a s solved. Tx.
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...