WinForm拖动没有标题栏窗体的方法


建立窗体的名称修改为:Form_HoverTree

文后附有源码下载。

主要代码:

 Point _HoverTreePosition;
        public Form_HoverTree()
        {
            InitializeComponent();
            _HoverTreePosition = new Point();

        }

        /// <summary>
        /// 记录鼠标起始位置 hovertree.com
        /// </summary>
        private void Form_HoverTree_MouseDown(object sender, MouseEventArgs e)
        {
            _HoverTreePosition.X = e.X;
            _HoverTreePosition.Y = e.Y;
        }

        /// <summary>
        /// 按住左键,鼠标移动窗体跟着移动 - 何问起 
        /// </summary>
        private void Form_HoverTree_MouseMove(object sender, MouseEventArgs e)
        {
            if(e.Button== MouseButtons.Left)
            {
                Point h_myPosittion = MousePosition;
                h_myPosittion.Offset(-_HoverTreePosition.X, -_HoverTreePosition.Y);
                Location = h_myPosittion;
            }
        }

效果图:

可以看出,这个窗体为自定义形状的窗体,没有标题栏。具体参考:http://hovertree.com/h/bjaf/52nadvt4.htm

源码下载:

http://hovertree.com/h/bjaf/j4wwteu3.htm

转自:http://hovertree.com/h/bjaf/qewlrgqx.htm

推荐:

http://www.cnblogs.com/roucheng/p/DataGridView.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM