如何在.net compact(WM5.0/6.0)项目里实现浮动窗体?

tmoonlight 2009-01-12 03:08:00
RT ,如果我建立一个类似于对话框的新窗体,如何让这个窗体浮动在父窗体上? PC winform很容易实现,但在windows mobile上 使用FormX.ShowDialog出来的窗体总是将父窗体完全覆盖了,希望有这方面经验的同学帮帮我!
...全文
70 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoyuzi 2009-01-14
  • 打赏
  • 举报
回复
另外
4.显示这个窗口要用Show方法不要用ShowDialog方法。
xiaoyuzi 2009-01-14
  • 打赏
  • 举报
回复
1. 将要漂浮的form的FormBorderStyle 属性设为None
2. 将要漂浮的form的Size改为你需要的窗口大小,Position改为要显示的窗口位置。
3. 加入类似如下代码
public partial class Form2 : Form
{
#region Native Platform Invoke

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

// For Windows Mobile, replace user32.dll with coredll.dll
[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("coredll.dll", SetLastError = true)]
private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);


[DllImport("coredll.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);


static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);

static readonly int GWL_STYLE = -16;

private readonly UInt32 WS_CAPTION = 0x00C00000;
private readonly UInt32 WS_BORDER = 0x00800000;
private readonly uint WS_MINIMIZEBOX = 0x00020000;

private readonly UInt32 SWP_SHOWWINDOW = 0x0040;


#endregion

public Form2()
{
InitializeComponent();

IntPtr hWnd = FindWindow(null, this.Text);

uint style = GetWindowLong(hWnd, GWL_STYLE);

style |= (WS_BORDER | WS_CAPTION & ~WS_MINIMIZEBOX);

SetWindowLong(hWnd, GWL_STYLE, style);

SetWindowPos(hWnd, HWND_TOP, this.Left, this.Top, this.Width, this.Height, SWP_SHOWWINDOW);

}
}
tmoonlight 2009-01-12
  • 打赏
  • 举报
回复
没人回答吗?这里没做.net compact的?
tmoonlight 2009-01-12
  • 打赏
  • 举报
回复
我也这么试过了,把装体锁定取消然后缩小,但是整个窗体在弹出时还是会覆盖整个屏幕
HDNGO 2009-01-12
  • 打赏
  • 举报
回复
没做到这么牛的。。就会做简单的~
hhxxcj 2009-01-12
  • 打赏
  • 举报
回复
你把要弹出来的窗体小于你窗体应该是可以的

17,741

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧