2

我的表单需要删除一些表单上的“x”-(“智能最小化”-实际上并不那么聪明)和“确定”按钮。不幸的是,当我这样做时,小键盘输入图标从中间移动到右侧,并且下栏变成灰色而不是黑色。

我希望能够删除最小化和确定控件(或只是覆盖它们的处理程序) - 但不幸的是我无法在 CF 中做到这一点。(大错特错,MS!)

有没有办法恢复一些 UI 的外观和感觉(比如黑条)?

就像我说的那样,理想情况下,我们希望将文本“确定”更改为其他单词,或者只是重载用户启动的最小化(单击 X 或确定)。

(我会尽量放一些屏幕截图来展示我在说什么)

编辑

另请注意,我在表单初始化的主菜单中添加了两项。

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

我遇到了类似的问题并努力寻找答案,直到我偶然发现以下网址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 回答
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);
  }
}
于 2011-11-01T16:15:33.680 回答