首页 > Windows开发 > 详细

C# window 窗体 保持最前显示

时间:2016-01-11 19:46:07      阅读:203      评论:0      收藏:0      [点我收藏+]
两句话搞定
[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吧  反正是主窗口
         
         }
    }
}

 

C# window 窗体 保持最前显示

原文:http://www.cnblogs.com/su-king/p/5122051.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!