PDA

View Full Version : انجام یک عمل هنگام بسته شدن فرم



saadatfar
دوشنبه 14 مرداد 1387, 20:00 عصر
من می خواهم هنگامی که فرم می خواهد بسته بشه یکسری عملیات انجام بشه باید چه کار کنم؟ یعنی وقتی کاربر دکمه close را زد.

jas1387
دوشنبه 14 مرداد 1387, 20:43 عصر
من می خواهم هنگامی که فرم می خواهد بسته بشه یکسری عملیات انجام بشه باید چه کار کنم؟ یعنی وقتی کاربر دکمه close را زد.

باید کدهای که می خواهی قبل از بسته شدن فرم اجرا بشود در همان رویداد و قبل از کد بستن بنویسید


Me.close

salehbagheri
دوشنبه 14 مرداد 1387, 22:17 عصر
مي توني به روش زير عمل كني!



Private Sub SubForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
Dim Response As MsgBoxResult
Response = MsgBox("Do you want to close this Form?" & vbCrLf & vbCrLf & "All unsaved data will be lost!", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2 Or MsgBoxStyle.Question, Me.Text)
If Response = MsgBoxResult.Yes Then
Exit Sub
ElseIf Response = MsgBoxResult.No Then
e.Cancel = True
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation And MsgBoxStyle.OkOnly, "Error")
End Try
End Sub