C# 窗口全屏、置顶、获取焦点

匿名 (未验证) 提交于 2019-12-02 23:43:01

很简单的几行代码

            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);         }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!