2011-10-31 31 views
2

我的表單需要刪除'x' - (「智能最小化」 - 實際上並不那麼聰明)和' OK「按鈕。不幸的是,當我這樣做時,小鍵盤輸入圖標從中間向右側移動,下部欄變爲灰色而不是黑色。如何保留ControlBox在COmpact Framework中設置爲false時的UI感覺(win mobile)

我想只能刪除最小化和確定控件(或只是重寫他們的處理程序) - 但不幸的是我無法在CF中這樣做。 (什麼錯誤,MS!)

有沒有辦法讓一些用戶界面的外觀和感覺(如黑色欄)?

就像我說過的,理想情況下,我們希望將文本「OK」改爲其他文字,或者只是超載用戶啓動的最小化(單擊X或OK)。

(我會盡量把一些屏幕截圖時,我可以顯示什麼我談論)

編輯

還請注意,我在窗體初始化增加了兩個項目主菜單。

// create three menu items to go at bottom of form/on main menu 
    // add new menu items to main menu 
    // get rid of 'X' (smart minimize) and OK controls 

    menuNext = new System.Windows.Forms.MenuItem(); 
    ... 

    mainMenu.MenuItems.Add(menuPrevious);    
    mainMenu.MenuItems.Add(menuNext); 
    mainMenu.MenuItems.Add(menuCancel); 

    MinimizeBox = false;       
    ControlBox = false; 

注意 我產生的形式和程序的項目 - 不與窗體設計器。這是一個要求,因爲這些表單是在運行時基於配置文件即時創建的。

+0

我無法使用模擬器重現此操作。我將ControlBox和MinimizeBox設置爲false,並按預期工作。 – yms

+0

@yms - 請注意,我還在主菜單中添加了一些菜單項。我認爲這也與它有關。但事情看起來很好,除非我刪除OK按鈕/ ControlBox – Tim

+0

即使添加菜單,我也無法再現此問題。但是我注意到,如果你在desginer上做同樣的事情,生成的代碼將總是在調用SuspendLayout()和調用ResumeLayout(false)之間完成所有這些操作。也許你可以嘗試做同樣的事情...... – yms

回答

1

添,這裏有一些P/Invoke電話,我發現有助於顯示&隱藏HHTaskBarMS_SIPBUTTON

[DllImport("coredll.dll", 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); 

[DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)] 
public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName); 

public enum WindowPosition { 
    SWP_HIDEWINDOW = 0x0080, 
    SWP_SHOWWINDOW = 0x0040 
} 

這裏是我寫它的包裝:

static IntPtr _taskBar; 
static IntPtr _sipButton; 
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) { 
    // log my Error (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) { 
    // log my Error Wrapper(enable ? "Show SIP" : "Hide SIP", err); 
    } 
} 

最後,這裏是我如何使用它:

/// <summary> 
/// The main entry point for the application. 
/// </summary> 
[MTAThread] 
static void Main() { 
    ShowWindowsMenu(false); 
    try { 
    Application.Run(new Form()); 
    } catch (Exception err) { 
    // Log my error 
    } finally { 
    ShowWindowsMenu(true); 
    } 
} 
+1

但這並不能保持控制箱的外觀和感覺。我的需要是他*想*保留標題欄和Windows圖標,他只是想完全刪除(ok)或(X)按鈕或覆蓋他們的行爲。 – ctacke

+0

也許有一些字符串引用(ok)或(X)按鈕(如'HHTaskBar'和'MS_SIPBUTTON')。如果他在任務期間絆倒了那些人,他可以修改我的'ShowWindowsMenu'來顯示和隱藏它們。 – jp2code

1

我有一個類似的問題,並在努力尋找答案,直到我偶然發現了以下網址http://msdn.microsoft.com/en-us/library/bb158579.aspx

它提到一個所謂的風格是WS_NONAVDONEBUTTON似乎適用於這個問題,但是這個代碼是爲C++。

看起來有人已經爲它寫了一個包裝,這解決了我所有的問題。

http://www.koders.com/csharp/fid55A69F22A80DB21F0DB8F0F3EAA3F7D17849142C.aspx?s=button#L8

爲了您的信息,我在基地形式的OnActivated覆蓋使用的HideXButton方法,突然X和O不再可見。

[DllImport("coredll.dll")] 
public static extern UInt32 SetWindowLong(
    IntPtr hWnd, 
    int nIndex, 
    UInt32 dwNewLong); 

[DllImport("coredll.dll")] 
public static extern UInt32 GetWindowLong(
    IntPtr hWnd, 
    int nIndex); 

public const int GWL_STYLE = -16; 
public const UInt32 WS_NONAVDONEBUTTON = 0x00010000; 

public static void HideXButton(IntPtr hWnd) 
{ 
    UInt32 dwStyle = GetWindowLong(hWnd, GWL_STYLE); 

    if ((dwStyle & WS_NONAVDONEBUTTON) == 0) 
     SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_NONAVDONEBUTTON); 
} 
+0

謝謝 - 我會研究一下。 – Tim

+0

我很害怕,但這對我不起作用。 –

相關問題