C#窗口任意位置拖动

作者:互联网   出处:控件中国网   2014-11-05 19:22:00   阅读:1

C#窗口任意位置拖动

注意要添加System.Runtime.InteropServices的引用

view sourceprint?using System; 

using System.Runtime.InteropServices; 

using System.Windows.Forms; 

  

namespace WindowsFormsApplication1 

    public partial class Form1 : Form 

    { 

        [DllImport("user32.dll")] 

        public static extern bool ReleaseCapture(); 

          

        [DllImport("user32.dll")] 

        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); 

        public const int WM_SYSCOMMAND = 0x0112; 

        public const int SC_MOVE = 0xF010; 

        public const int HTCAPTION = 0x0002; 

  

        public Form1() 

        { 

            InitializeComponent(); 

        } 

  

        private void Form1_MouseDown(object sender, MouseEventArgs e) 

        { 

            ReleaseCapture(); 

            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); 

        } 

    } 

}

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat