C# window 窗體 保持最前顯示


兩句話搞定
[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);

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

namespace test
{
    public partial class Form1 : Form
    {
        [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);

        public Form1()
        {
            InitializeComponent(); 
        }

         protected override void OnLoad(EventArgs e)    
         {
             SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后參數也有用1 | 4 p1.MainForm.Handle  我記得這個是MainForm吧  反正是主窗口
             SetWindowPos(this.printPreviewDialog1.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后參數也有用1 | 4 p1.MainForm.Handle  我記得這個是MainForm吧  反正是主窗口
         
         }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM