Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Break a Method???

Break a Method???

Scheduled Pinned Locked Moved C#
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    S K Y
    wrote on last edited by
    #1

    I need to break entire method when I click cancel. But when I put break its break if else part only. How can I break entire method?

    private void NT_FormClosed(object sender, FormClosedEventArgs e)
    {
    MessageBox.Show("Do you want to close the program?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2); {
    if(DialogResult == DialogResult.Yes)
    {
    Save(sender);
    }
    if (DialogResult == DialogResult.Cancel)
    {
    Break; :doh:
    }
    }
    }

    A S E L A

    N 1 Reply Last reply
    0
    • S S K Y

      I need to break entire method when I click cancel. But when I put break its break if else part only. How can I break entire method?

      private void NT_FormClosed(object sender, FormClosedEventArgs e)
      {
      MessageBox.Show("Do you want to close the program?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2); {
      if(DialogResult == DialogResult.Yes)
      {
      Save(sender);
      }
      if (DialogResult == DialogResult.Cancel)
      {
      Break; :doh:
      }
      }
      }

      A S E L A

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      return; :)

      Navaneeth How to use google | Ask smart questions

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        return; :)

        Navaneeth How to use google | Ask smart questions

        S Offline
        S Offline
        S K Y
        wrote on last edited by
        #3

        No cannot. when i use return still same.its all the way close the application. i want to continue application running when user click cancel.

        A S E L A

        N 1 Reply Last reply
        0
        • S S K Y

          No cannot. when i use return still same.its all the way close the application. i want to continue application running when user click cancel.

          A S E L A

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          FormClosed event handler is too late to cancel form closing. Try FormClosing[^] event. You can use FormClosingEventArgs.Cancel property to cancel the form closing.

          Navaneeth How to use google | Ask smart questions

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups