首先,这些天我只运行 Windows Mobile 5 (WM5)。(几年前我必须从 PocketPC 2003 升级。哈哈)
我发现定义窗体的窗口大小在移动设备上效果不佳,并且显示/隐藏多个窗体很尴尬,并且永远不会按照您想要的方式运行。
不过,请确保您的 Main Form 已WindowState
设置为Maximized。
如果有帮助,我还将ControlBox
and设置MinimizeBox
为False 。
如果您只是将面板用作您的表单,而将主表单用作某种 MDI 容器(单词选择不好,但这就是我正在做的),那么它看起来会更好,而不是使用多个表单。
在我的Designer View中,每个面板只是一个装满控件的小盒子。
- 要使用每个面板,请在Visual Studio设计器中选择它,您将看到一个位置框(上下箭头和左右箭头)。
- 右键单击位置框,然后单击置于前面。
- 现在转到面板控件的 Properties 并设置
Dock
为Fill。
- 虽然此面板是全屏的,但请使用适当的名称添加所有按钮、文本框等。
pnl1_button1
与VSpnl2_button1
默认button1
和button2
.
- 完成此面板的设计视图后,返回
Dock
属性并将其设置回None。
- 继续下一个面板控件。
我发现它还有助于维护面板的小草图以及它们的名称和控件的名称。
如果Load
是主窗体,请将 everyPanel
的Dock
属性设置为DockStyle.Fill。然后,当您想显示一种形式时,只需调用Panel1.BringToFront()
而不是dialog.Show()
.
移动开发并不难,但它是不同的。:)
编辑:
在项目的Program.cs文件中,我保留了以下静态工具,可用于打开和关闭“开始”菜单(在 WM5 中效果不佳,但我的 PocketPC 版本的代码中仍然有它)。
一年左右我还没有打开这个项目,但它应该都是有效的。试一试。如果我遗漏了什么,请告诉我。
将其粘贴到项目的Program.cs文件中后,只需Program.ShowWindowsMenu(false);
在程序启动和Program.ShowWindowsMenu(true);
程序退出时调用。
static IntPtr _taskBar;
static IntPtr _sipButton;
public enum Notify_Events {
NOTIFICATION_EVENT_NONE = 0,
NOTIFICATION_EVENT_TIME_CHANGE = 1,
NOTIFICATION_EVENT_SYNC_END = 2,
NOTIFICATION_EVENT_DEVICE_CHANGE = 7,
NOTIFICATION_EVENT_RS232_DETECTED = 9,
NOTIFICATION_EVENT_RESTORE_END = 10,
NOTIFICATION_EVENT_WAKEUP = 11,
NOTIFICATION_EVENT_TZ_CHANGE = 12,
NOTIFICATION_EVENT_OFF_AC_POWER,
NOTIFICATION_EVENT_ON_AC_POWER
}
public enum WindowPosition {
SWP_HIDEWINDOW = 0x0080,
SWP_SHOWWINDOW = 0x0040
}
[DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);
[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);
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);
}
}
static void ErrorWrapper(string routine, Exception e) {
if (!String.IsNullOrEmpty(e.Message)) {
MessageBox.Show(e.Message, routine, MessageBoxButtons.OKCancel, MessageBoxIcon.None, 0);
}
}
编辑2:
声明主表单的私有静态实例,然后将其包装在项目Program.cs
文件中的 try....catch 例程中,如下所示:
static Form1 ppcForm = null;
static void Main() {
ShowWindowsMenu(false);
try {
ppcForm = new Form1();
Application.Run(ppcForm );
} catch (Exception err) {
if (!String.IsNullOrEmpty(err.Message)) {
ErrorWrapper("Mobile Form (Program)", err);
}
} finally {
ShowWindowsMenu(true);
}
}