vb setwindowpos_insertinto_setwindowpos

电脑杂谈  发布时间:2017-01-22 14:18:54  来源:网络整理

setwindowpossetwindowpos

[DllImport("user32.dll", CharSet = CharSet.Auto)]

private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);

/// <summary>

/// 得到当前活动的窗口

/// </summary>

vb setwindowpos_insertinto_setwindowpos

/// <returns></returns>

[DllImport("user32.dll", CharSet = CharSet.Auto)]

private static extern System.IntPtr GetForegroundWindow();

哪个窗体想要置顶,在Form_Load中加上

SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后参数也有用1 | 4

setwindowpos_vb setwindowpos_insertinto

具体说明,看API函数说明

如果是用点击一个按钮后弹出新窗体,并置顶,则:

Form2 frm = new Form2();

frm.Show();

SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);

这样,新打开的窗体就是置顶了


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-28061-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 张淞寒
        张淞寒

        一切爱好和平与尊重他国领土主权的国家

      • 安妮海瑟薇
        安妮海瑟薇

        美帝得逞了

      热点图片
      拼命载入中...