當您爲FormClosing
和FormClosed
事件編寫代碼時,是否記得將實際形式連接起來以使用它們?
我有幾個Windows Mobile應用程序,我維護,他們調用我爲他們創建的方法。
我經常忘記設置控件以使用我爲他們編寫的代碼,所以這是我第一次想到的。
編輯:我不使用微軟的OK
按鈕,而是使用具有EXIT菜單項的菜單。
![Wm5 in GUI](https://i.stack.imgur.com/rK6AL.png)
我也/關閉軟輸入面板(SIP)和任務欄被P調用「coredll」文件中的Program.cs
文件我的主要程序執行之前。
這可能是您的解決方案。如果是這樣,這應該是我使用的所有代碼。一定要測試一下,如果有什麼遺漏,請告訴我,我會更新它。
const string COREDLL = "coredll.dll";
[DllImport(COREDLL, EntryPoint = "FindWindowW", SetLastError = true)]
public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);
[DllImport(COREDLL, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
private static Form1 objForm = null;
private static IntPtr _taskBar = IntPtr.Zero;
private static IntPtr _sipButton = IntPtr.Zero;
[MTAThread]
static void Main() {
ShowWindowsMenu(false);
try {
objForm = new Form1();
Application.Run(objForm);
} catch (Exception err) {
objForm.DisableTimer();
if (!String.IsNullOrEmpty(err.Message)) {
ErrorWrapper("AcpWM5 Form (Program)", err);
}
} finally {
ShowWindowsMenu(true); // turns the menu back on
}
}
private static void ShowWindowsMenu(bool enable) {
try {
if (enable) {
if (_taskBar != IntPtr.Zero) {
SetWindowPos(_taskBar, IntPtr.Zero, 0, 0, 240, 26, (int)WindowPosition.SWP_SHOWWINDOW); // display the start bar
}
} else {
_taskBar = FindWindowCE("HHTaskBar", null); // Find the handle to the Start Bar
if (_taskBar != IntPtr.Zero) { // If the handle is found then hide the start bar
SetWindowPos(_taskBar, IntPtr.Zero, 0, 0, 0, 0, (int)WindowPosition.SWP_HIDEWINDOW); // Hide the start bar
}
}
} catch (Exception err) {
ErrorWrapper(enable ? "Show Start" : "Hide Start", err);
}
try {
if (enable) {
if (_sipButton != IntPtr.Zero) { // If the handle is found then hide the start bar
SetWindowPos(_sipButton, IntPtr.Zero, 0, 0, 240, 26, (int)WindowPosition.SWP_SHOWWINDOW); // display the start bar
}
} else {
_sipButton = FindWindowCE("MS_SIPBUTTON", "MS_SIPBUTTON");
if (_sipButton != IntPtr.Zero) { // If the handle is found then hide the start bar
SetWindowPos(_sipButton, IntPtr.Zero, 0, 0, 0, 0, (int)WindowPosition.SWP_HIDEWINDOW); // Hide the start bar
}
}
} catch (Exception err) {
ErrorWrapper(enable ? "Show SIP" : "Hide SIP", err);
}
}
您是不是要找「確定」按鈕或「X」,IIRC當你點擊「X」按鈕您的應用程序不緊密,它只是隱藏的,所以當用戶再次運行它,它只是帶來了回到頂部。我認爲「確定」按鈕僅顯示在對話窗口中。 – Matt
IIRC < - 按鈕實際上關閉了應用程序或應用程序的當前窗口。 –
這是「確定」按鈕。我的應用程序是*不*模態。 –