C# 解决调用winform窗体顶置且解决任务栏图片显示问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 解决调用winform窗体顶置且解决任务栏图片显示问题相关的知识,希望对你有一定的参考价值。

窗体顶置两种方法:

方法1:

/// <summary>   

/// 设置当前活动的窗口   

/// </summary>   

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

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

private static extern System.IntPtr GetForegroundWindow();

private void MainFrm_Load(object sender, EventArgs e)

{

 SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2);

}


方法2:

private void testBtn_Click(object sender, EventArgs e)

{

Form2 frm = new Form2();   

frm.Show();   

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

}


解决任务栏图片显示有时失效方法:

private void testBtn_Click(object sender, EventArgs e)

{

this.Close();

Form2 frm = new Form2(); 

frmShowInTaskbar = false;

frm.Show();

frm.ShowInTaskbar = true;

}

本文出自 “小森工作室” 博客,谢绝转载!

以上是关于C# 解决调用winform窗体顶置且解决任务栏图片显示问题的主要内容,如果未能解决你的问题,请参考以下文章