2

私のフォームでは、いくつかのフォームで「x」(「スマート最小化」 - 実際にはそれほどスマートではない) と「OK」ボタンを削除する必要があります。残念ながら、そうすると、小さなキーボード入力アイコンが中央から右側に移動し、下部のバーが黒ではなく灰色に変わります。

最小化コントロールと OK コントロールを削除したい (またはそれらのハンドラーをオーバーライドしたい) だけですが、残念ながら CF ではそれができません。(なんてミスだ、MS!)

UI のルック アンド フィール (黒いバーなど) を元に戻す方法はありますか?

私が言ったように、理想的には、「OK」というテキストを他の単語に変更するか、ユーザーが開始した最小化 (X または OK をクリック) をオーバーロードするだけです。

(私が話していることを示すことができる場合は、スクリーンショットをいくつか掲載しようとします)

編集

また、フォームの初期化でメイン メニューに 2 つの項目を追加したことにも注意してください。

    // 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;

注: フォーム デザイナーではなく、プログラムでフォームとアイテムを生成します。これらのフォームは実行時に構成ファイルに基づいてオンザフライで作成されるため、これは必須です。

4

2 に答える 2

1

ティム、ここP/Invokeに私が表示および非表示にするのに役立つと思ったいくつかの呼び出しがありHHTaskBarますMS_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);
  }
}
于 2011-11-01T16:15:33.680 に答える
1

私は同様の問題を抱えていて、次の URL 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 と Ok が表示されなくなりました。

[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);
}
于 2012-03-18T23:28:25.230 に答える