Problem in Window Closing

  • Thread starter Thread starter Amalorpavanathan Y \(Amal\)
  • Start date Start date
A

Amalorpavanathan Y \(Amal\)

Hi All,
In Winform Application, MDI form is having Save button.
When i close the application, it will ask Save Changes?
YES or NO or CANCEL.
after i select CANCEL button, i have set e.Cancel = True
So application will work continously,
But Save button Event is working.
Can anybody give me the solution for this situation?

Regards,
Amal
 
* "Amalorpavanathan Y \(Amal\) said:
In Winform Application, MDI form is having Save button.
When i close the application, it will ask Save Changes?
YES or NO or CANCEL.
after i select CANCEL button, i have set e.Cancel = True
So application will work continously,
But Save button Event is working.
Can anybody give me the solution for this situation?

"Post code."
 
Private Sub TEST_Closing(ByVal sender As Object, ByVal
e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
If Me.gdstTEST.HasChanges() Then
Select Case (MessageBox.Show(" Do you want to
save the changes that you made ", "Test",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1))
Case DialogResult.Yes
Me.DoSave()
Case DialogResult.No
Me.gdstTEST.RejectChanges()
Me.Close()
Case DialogResult.Cancel
e.Cancel = True
End Select
End If
End Sub
 
* "Amalorpavanathan Y \(AMAL\) said:
Private Sub TEST_Closing(ByVal sender As Object, ByVal
e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
If Me.gdstTEST.HasChanges() Then
Select Case (MessageBox.Show(" Do you want to
save the changes that you made ", "Test",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1))
Case DialogResult.Yes
Me.DoSave()
Case DialogResult.No
Me.gdstTEST.RejectChanges()
Me.Close()
Case DialogResult.Cancel
e.Cancel = True
End Select
End If
End Sub

And where is the "Save" button?
 
Hi Herfried,

Sorry, Thank you for your immediate reponse.
i have solved this problem,

Please see the save event below

(MDI form save button in toolbar)
when i click the save button, event flow like

step 1:

Private Sub TEST_Closing(ByVal sender As Object, ByVal
e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
If Me.gdstTEST.HasChanges() Then
Select Case (MessageBox.Show(" Do you want to
save the changes that you made ", "Test",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1))
Case DialogResult.Yes
Me.DoSave()
Case DialogResult.No
Me.gdstTEST.RejectChanges()
Me.Close()
Case DialogResult.Cancel
e.Cancel = True
End Select
End If
End Sub

step 2:

Public Sub UnhookAllActions() Implements
IToolbarActionManager.UnhookAllActions
saveAction = Nothing
deleteAction = Nothing
clearAction = Nothing
End Sub

step 3:
Private saveAction As Core.ToolbarAction
Private deleteAction As Core.ToolbarAction
Private clearAction As Core.ToolbarAction

Private Sub ToolBar_ButtonClick(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar.ButtonClick
If e.Button.Text = "Save" And Not saveAction Is
Nothing Then
saveAction()
ElseIf e.Button.Text = "Clear" And Not clearAction
Is Nothing Then
clearAction()
ElseIf e.Button.Text = "Delete" And Not
deleteAction Is Nothing Then
deleteAction()
End If
End Sub

when i click the save button, saveAction will be maked
as nothing,
So the event has not been worked. i resolved this problem.

Thank you
 
Back
Top