winform窗体的伸缩

来源:互联网 发布:淘宝如何开企业店铺 编辑:程序博客网 时间:2024/05/02 02:09

 

//picDragFlag是一个图片控件,为其添加鼠标移动事件

 private void picDragFlag_MouseMove(object sender, MouseEventArgs e)
 {

            //当窗体达到最小时,则不能再拉伸
            if (e.Button == MouseButtons.Left && this.Width>180&& this.Height>180)
            {
              
                this.Width += e.Location.X;
                this.Height += e.Location.Y;


            }//当达到最小时,可以拉伸
            else if (e.Button == MouseButtons.Left && e.X > 0 && e.Y > 0)
            {
                this.Width += e.Location.X;
                this.Height += e.Location.Y;
            }

}

e.X与e.Y

//
        // 摘要:
        //     获取鼠标在产生鼠标事件时的 x 坐标。
        //
        // 返回结果:
        //     鼠标的 X 坐标(以像素为单位)。

我发现它返回的应该是以鼠标单击的控件的左上角为原点,鼠标单击的地方的坐标(是个相对坐标)。

原创粉丝点击