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. FormClosingEvent

FormClosingEvent

Scheduled Pinned Locked Moved C#
7 Posts 5 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.
  • H Offline
    H Offline
    h s n
    wrote on last edited by
    #1

    I have File-Exit Menu. In this menu I want to invoke FormClosingEvent. Please tell me how can call that event from From File-Exit Menu. I dont know what to write in enum CloseReason. private void FileExit_Click(object sender, EventArgs e) { //here i want to call FormClosing event } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (dirty == true) { DialogResult res = SaveDialog(); if (res == DialogResult.Yes) { SaveFile(); e.Cancel = false; } if (res == DialogResult.No) { e.Cancel = false; } if (res == DialogResult.Cancel) { e.Cancel = true; } } }

    S Q 2 Replies Last reply
    0
    • H h s n

      I have File-Exit Menu. In this menu I want to invoke FormClosingEvent. Please tell me how can call that event from From File-Exit Menu. I dont know what to write in enum CloseReason. private void FileExit_Click(object sender, EventArgs e) { //here i want to call FormClosing event } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (dirty == true) { DialogResult res = SaveDialog(); if (res == DialogResult.Yes) { SaveFile(); e.Cancel = false; } if (res == DialogResult.No) { e.Cancel = false; } if (res == DialogResult.Cancel) { e.Cancel = true; } } }

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Call Close method of your main form.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      H 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Call Close method of your main form.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        H Offline
        H Offline
        h s n
        wrote on last edited by
        #3

        Thank u. FormClosedEventArgs ev = new FormClosedEventArgs(/*??? */); MainForm_FormClosed(sender, ev); Please tell me how can i call? What to write in argument, wat to write in CloseReason?

        L L 2 Replies Last reply
        0
        • H h s n

          Thank u. FormClosedEventArgs ev = new FormClosedEventArgs(/*??? */); MainForm_FormClosed(sender, ev); Please tell me how can i call? What to write in argument, wat to write in CloseReason?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          try one of these: myMainForm.Close(); Close(); // inside main form class Application.Exit(); :)

          Luc Pattyn

          H 1 Reply Last reply
          0
          • L Luc Pattyn

            try one of these: myMainForm.Close(); Close(); // inside main form class Application.Exit(); :)

            Luc Pattyn

            H Offline
            H Offline
            h s n
            wrote on last edited by
            #5

            oooh very thanks. :) I am still new with C# after 2 months :)

            1 Reply Last reply
            0
            • H h s n

              Thank u. FormClosedEventArgs ev = new FormClosedEventArgs(/*??? */); MainForm_FormClosed(sender, ev); Please tell me how can i call? What to write in argument, wat to write in CloseReason?

              L Offline
              L Offline
              Luis Alonso Ramos
              wrote on last edited by
              #6

              Just call Close on your File Exit handler. It will try to close the form, raising the Closing event in the process. If nothing cancels the closing, then you get the Closed event. You don't have to call your Closing event handler manually.

              Luis Alonso Ramos Intelectix Chihuahua, Mexico

              Not much here: My CP Blog!

              1 Reply Last reply
              0
              • H h s n

                I have File-Exit Menu. In this menu I want to invoke FormClosingEvent. Please tell me how can call that event from From File-Exit Menu. I dont know what to write in enum CloseReason. private void FileExit_Click(object sender, EventArgs e) { //here i want to call FormClosing event } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (dirty == true) { DialogResult res = SaveDialog(); if (res == DialogResult.Yes) { SaveFile(); e.Cancel = false; } if (res == DialogResult.No) { e.Cancel = false; } if (res == DialogResult.Cancel) { e.Cancel = true; } } }

                Q Offline
                Q Offline
                qingfengliuyue
                wrote on last edited by
                #7

                I think you can send the win32AI message "WM_CLOSE" when the button is clicked like a function in win32 SDK "SendMessage()" function: like this: // define [DllImport("User32.dll")] public static extern IntPtr FindWindow(String lpClassName, String lpWindowName); [DllImport("User32.dll")] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); const int WM_LBUTTONDOWN = 0x201; const int WM_LBUTTONUP = 0x0202; // sample, u should use spy++ to find windows class name and control class name IntPtr hwndWin = FindWindow("TfrmMain", "window title"); if (hwndWin.Equals(IntPtr.Zero) == false) { IntPtr hwndBtn = FindWindowEx(hwndWin, IntPtr.Zero, "TButton", "control text"); if (hwndBtn.Equals(IntPtr.Zero) == false) { SendMessage(hwndBtn, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero); SendMessage(hwndBtn, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero); } }

                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