FormClosingEvent
-
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; } } }
-
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; } } }
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
-
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
-
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?
try one of these: myMainForm.Close(); Close(); // inside main form class Application.Exit(); :)
Luc Pattyn
-
try one of these: myMainForm.Close(); Close(); // inside main form class Application.Exit(); :)
Luc Pattyn
-
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?
Just call
Close
on your File Exit handler. It will try to close the form, raising theClosing
event in the process. If nothing cancels the closing, then you get theClosed
event. You don't have to call yourClosing
event handler manually.Luis Alonso Ramos Intelectix Chihuahua, Mexico
Not much here: My CP Blog!
-
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; } } }
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); } }