e.Cancel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl

    e.Cancel

    Hi you al
    I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goe

    ' Calls this method from the InitializeCompo nent() method of your form
    Private Sub OtherInitialize (
    AddHandler Me.Closing, AddressOf Me.Form1_Cance
    End Sub 'OtherInitializ

    Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs
    If Not myDataIsSaved The
    e.Cancel = Tru
    MessageBox.Show ("You must save first."
    Els
    e.Cancel = Fals
    MessageBox.Show ("Goodbye."
    End I
    End Sub 'Form1_Cance

    Forget about the myDataIsSaved stuff. I am trying to know where in the form to put the "Sub OtherInitialize ". where ito call it from and to put the "Protected Sub Form1_Cancel
    Thank

  • Cor Ligthert

    #2
    Re: e.Cancel

    Hi Carl,
    [color=blue]
    > I am new to this stuff and I found this code to close a form in the help[/color]
    files and I do not understand it or where its goes

    You do not need that, just open in your form code the uper left combobox and
    choose form1_events. Than in the right combobox "Closing"

    The sub with the handler in it will be completly made. There you can paste
    in the syntax you have now in the sub Form_Cancel (Than others will probably
    as well understand better your code, en needed by instance when you send a
    snippet to this newsgroup).

    You can as well delete that first sub and set the addhandler sentence in
    the load event from your page, however it is than a little bit not done
    code.

    I hope this helps?

    Cor
    [color=blue]
    >
    > ' Calls this method from the InitializeCompo nent() method of your form.
    > Private Sub OtherInitialize ()
    > AddHandler Me.Closing, AddressOf Me.Form1_Cancel
    > End Sub 'OtherInitializ e
    >
    > Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
    > If Not myDataIsSaved Then
    > e.Cancel = True
    > MessageBox.Show ("You must save first.")
    > Else
    > e.Cancel = False
    > MessageBox.Show ("Goodbye.")
    > End If
    > End Sub 'Form1_Cancel
    >
    > Forget about the myDataIsSaved stuff. I am trying to know where in the[/color]
    form to put the "Sub OtherInitialize ". where ito call it from and to put the
    "Protected Sub Form1_Cancel"[color=blue]
    > Thanks
    >[/color]


    Comment

    • Armin Zingler

      #3
      Re: e.Cancel

      "Carl" <anonymous@disc ussions.microso ft.com> schrieb[color=blue]
      > Hi you all
      > I am new to this stuff and I found this code to close a form in the
      > help files and I do not understand it or where its goes
      >
      > ' Calls this method from the InitializeCompo nent() method of your
      > form. Private Sub OtherInitialize ()
      > AddHandler Me.Closing, AddressOf Me.Form1_Cancel
      > End Sub 'OtherInitializ e
      >
      > Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
      > If Not myDataIsSaved Then
      > e.Cancel = True
      > MessageBox.Show ("You must save first.")
      > Else
      > e.Cancel = False
      > MessageBox.Show ("Goodbye.")
      > End If
      > End Sub 'Form1_Cancel
      >
      > Forget about the myDataIsSaved stuff. I am trying to know where in
      > the form to put the "Sub OtherInitialize ". where ito call it from and
      > to put the "Protected Sub Form1_Cancel" Thanks[/color]

      What's your intention? To close a Form, call it's Close method. The closing
      event occurs before the Form get's closed. In the event handler you can set
      e.cancel = true to stop the Form from being closed. If it is closed, the
      Closed event occurs.


      --
      Armin

      How to quote and why:



      Comment

      • Cor Ligthert

        #4
        OT

        Hi Armin,

        I saw this message at 10:37 (our time) is there something strange or is this
        normal?

        While I had seen the message from Pieter (DraguVaso) before that in an
        earlier refresh.

        Cor


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: e.Cancel

          * "=?Utf-8?B?Q2FybA==?=" <anonymous@disc ussions.microso ft.com> scripsit:[color=blue]
          > I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goes
          >
          > ' Calls this method from the InitializeCompo nent() method of your form.
          > Private Sub OtherInitialize ()
          > AddHandler Me.Closing, AddressOf Me.Form1_Cancel[/color]

          This adds a handler to the form's 'Closing' event. This event is fired
          when the user or the system is trying to close the form.
          [color=blue]
          > End Sub 'OtherInitializ e
          >
          > Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
          > If Not myDataIsSaved Then[/color]

          'myDataSaved' is a private variable of type 'Boolean' that is set if
          data has been saved. If it's not yet saved, a messagebox is shown that
          tells the user to save data. In the saving procedure, the Boolean
          variable is set.
          [color=blue]
          > e.Cancel = True
          > MessageBox.Show ("You must save first.")
          > Else[/color]

          Data been saved, so exit-
          [color=blue]
          > e.Cancel = False
          > MessageBox.Show ("Goodbye.")
          > End If
          > End Sub 'Form1_Cancel
          >
          > Forget about the myDataIsSaved stuff. I am trying to know where in the form to put the "Sub OtherInitialize ". where ito call it from and to put the "Protected Sub Form1_Cancel"
          > Thanks[/color]

          You put it after the call to 'InitializeComp onent' in your 'Sub New'.

          --
          Herfried K. Wagner [MVP]
          <URL:http://dotnet.mvps.org/>

          Comment

          • Cor Ligthert

            #6
            Re: e.Cancel

            Hi Herfried,

            I did advice 3 hours ago not to use this method, can you descibe why it
            should be done in this way and not in the way as it is build in by
            Microsoft?

            Cor
            [color=blue]
            > * "=?Utf-8?B?Q2FybA==?=" <anonymous@disc ussions.microso ft.com> scripsit:[color=green]
            > > I am new to this stuff and I found this code to close a form in the help[/color][/color]
            files and I do not understand it or where its goes[color=blue][color=green]
            > >
            > > ' Calls this method from the InitializeCompo nent() method of your form.
            > > Private Sub OtherInitialize ()
            > > AddHandler Me.Closing, AddressOf Me.Form1_Cancel[/color]
            >
            > This adds a handler to the form's 'Closing' event. This event is fired
            > when the user or the system is trying to close the form.
            >[color=green]
            > > End Sub 'OtherInitializ e
            > >
            > > Protected Sub Form1_Cancel(se nder As Object, e As CancelEventArgs )
            > > If Not myDataIsSaved Then[/color]
            >
            > 'myDataSaved' is a private variable of type 'Boolean' that is set if
            > data has been saved. If it's not yet saved, a messagebox is shown that
            > tells the user to save data. In the saving procedure, the Boolean
            > variable is set.
            >[color=green]
            > > e.Cancel = True
            > > MessageBox.Show ("You must save first.")
            > > Else[/color]
            >
            > Data been saved, so exit-
            >[color=green]
            > > e.Cancel = False
            > > MessageBox.Show ("Goodbye.")
            > > End If
            > > End Sub 'Form1_Cancel
            > >
            > > Forget about the myDataIsSaved stuff. I am trying to know where in the[/color][/color]
            form to put the "Sub OtherInitialize ". where ito call it from and to put the
            "Protected Sub Form1_Cancel"[color=blue][color=green]
            > > Thanks[/color]
            >
            > You put it after the call to 'InitializeComp onent' in your 'Sub New'.
            >[/color]


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: e.Cancel

              * "Cor Ligthert" <notfirstname@p lanet.nl> scripsit:[color=blue]
              > I did advice 3 hours ago not to use this method, can you descibe why it
              > should be done in this way and not in the way as it is build in by
              > Microsoft?[/color]

              Using 'Handles' is not much different from using 'AddHandler'. I would
              do that the way you described too, but I thought it's still important to
              tell the OP what the code is doing.

              Just my 2 Euro cents...

              --
              Herfried K. Wagner [MVP]
              <URL:http://dotnet.mvps.org/>

              Comment

              Working...