C# 窗口全屏、置頂、獲取焦點


很簡單的幾行代碼

            this.FormBorderStyle = FormBorderStyle.None;     //設置窗體為無邊框樣式  
            this.WindowState = FormWindowState.Maximized;    //最大化窗體 
            this.TopMost = true;                            //設置窗體置頂

始終獲取焦點

        //調用API
        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow(); //獲得本窗體的句柄
        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);//設置此窗體為活動窗體
        //定義變量,句柄類型
        public IntPtr Handle1;

        public Form1()
        {

            InitializeComponent();
            
        //    this.FormBorderStyle = FormBorderStyle.None;     //設置窗體為無邊框樣式  
          //  this.WindowState = FormWindowState.Maximized;    //最大化窗體 
            this.TopMost = true;                            //設置窗體置頂
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Handle1 = this.Handle;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //設置此窗體為活動窗體
            SetForegroundWindow(Handle1);
        }

 


免責聲明!

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



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