Jump to content

Въпрос за Visual Basic


Препоръчан пост

Здравейте! Тук съм за да попитам нещо, което ми привлече вниманието, но не можах да го направя, та... Въпроса ми е следния, как да направя така, че при натискане на хикса за изход от програмата да те пита дали си съгласен да я напуснеш с "Yes/No" question? Ако на някой му се занимава, нека ми опише малко по-подробно как да постигна този ефект, благодаря. :beer:
Link to comment
Сподели другаде

Public Class Form1

   Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

       If e.CloseReason = CloseReason.UserClosing Then
           Dim NeedsSave As Boolean = False
           'Perform contextual validations here and (re)set NeedsSave accordingly...

           NeedsSave = True '<-- Testing value.
           If NeedsSave Then

               Dim result As DialogResult = MessageBox.Show("You have some unsaved changes.  " _
                & "Do you want to save them now?", "Unsaved Changes", MessageBoxButtons.YesNoCancel, _
                MessageBoxIcon.Information)

               Select Case result
                   Case Windows.Forms.DialogResult.Cancel
                       'Cancel the form closing.
                       e.Cancel = True
                       Return

                   Case Windows.Forms.DialogResult.Yes
                       If SaveChanges() = False Then
                           'The user should still be able to cancel out here so
                           'that hanges are not lost (as long as the user can 
                           'perform the changes.
                           If MessageBox.Show("The save failed.  Do you still want close?", _
                           "Save Failed", MessageBoxButtons.OKCancel) = Windows.Forms.DialogResult.Cancel Then
                               e.Cancel = True
                               Return
                           Else
                               'Allow the form to close.
                           End If
                       End If

                   Case Else
                       'Allow the form to close.
               End Select
               
           End If
       End If
   End Sub



   Private Function SaveChanges() As Boolean
       'Place save algorithm here...
       'True = success, False means the save failed.

       Return False '<--For testing.
   End Function

End Class

 

Ето на някой ако му трябва в случай, че има желание да си го направи да го пита дали иска да се запазват промените преди изход от програмата.

Link to comment
Сподели другаде

  • 6 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гост
Отговори на тази тема

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   Не можете да качите директно снимка. Качете или добавете изображението от линк (URL)

Loading...
×
×
  • Създай ново...