首页 何问起 前端特效 htbtn-4 闪电 使用方法

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

posted @ 2016-12-17 12:32  roucheng  阅读(1954)  评论(2编辑  收藏  举报