首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >手写代码实现窗体的拖动效果

手写代码实现窗体的拖动效果

作者头像
liulun
发布于 2022-05-09 11:26:37
发布于 2022-05-09 11:26:37
7930
举报
文章被收录于专栏:liulunliulun
代码语言:javascript
复制
    public partial class Form1 : Form
    {
        private Point oldPoint = new Point(0,0);
        public Form1()
        {
            InitializeComponent();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.Close();
        }

        private void linkLabel2_MouseDown(object sender, MouseEventArgs e)
        {
            oldPoint.X = Cursor.Position.X;
            oldPoint.Y = Cursor.Position.Y;
        }

        private void linkLabel2_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                int offset_x = Cursor.Position.X-oldPoint.X;
                int offset_y = Cursor.Position.Y -oldPoint.Y;
                this.Location = new Point(this.Location.X + offset_x, this.Location.Y + offset_y);
                oldPoint.X = Cursor.Position.X;
                oldPoint.Y = Cursor.Position.Y;
            }
        }
    }
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2010-01-22,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档