调用WindowsAPI使窗体始终保持置顶效果,不被其他窗体遮盖:
[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>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern System.IntPtr GetForegroundWindow();
使用方式:在需要置顶的窗体的Load方法里面加上
//Load
private void Form1_Load(object sender, EventArgs e)
{
try
{
SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//3764
}
————————————————
版权声明:本文为CSDN博主「Hilary-He」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/heyangyi_19940703/article/details/52945739