C# 新建窗体,关闭主窗体,子窗体不关闭的方法及winform 怎么让窗体蹦到前面

发布时间 2023-07-07 11:58:57作者: 青丝·旅人

 

C# 新建窗体,关闭主窗体,子窗体不关闭的方法

                                Thread T = new Thread(new ThreadStart(() =>
                                {
                                    Application.Run(new Report.Report_UsuallyUsed());
                                }))
                                { IsBackground = true };
                                T.Start();

 

C# winform 怎么让窗体蹦到前面

方法一

 

[DllImport("user32.dll")]
[return:
MarshalAs(UnmanagedType.Bool)]
static
extern
bool
SetForegroundWindow(IntPtr
hWnd);


//这样调用:(Handle是窗口句柄)
SetForegroundWindow(this.Handle);

 

方法二

//当前窗体是this
this.Activate();

 

方法三

//当前窗体是this,此方法在下一次操作窗体之前,窗体都是最前的。
this.TopMost=true;
this.TopMost=false;