• winform 设置移动窗体


    private Point mouseOffset;
    private bool isMouseDown = false;
    public Form1()
    {
    InitializeComponent();
    }



    private void button2_Click(object sender, EventArgs e)
    {
    Close();
    }

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
    int yOffset, xOffset;
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
    xOffset
    = -e.X - SystemInformation.FrameBorderSize.Width;
    yOffset
    = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
    mouseOffset
    = new Point(xOffset, yOffset);
    isMouseDown
    = true;
    }
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
    if(e.Button == System.Windows.Forms.MouseButtons.Left)
    {
    isMouseDown
    = false;
    }
    }

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
    if (isMouseDown)
    {
    Point p
    = Control.MousePosition;
    p.Offset(mouseOffset.X,mouseOffset.Y);
    Location
    = p;
    }
    }
    }
  • 相关阅读:
    闭包问题小总结
    git常用命令总结
    数组对象方法的使用
    JS截取URL参数
    CSS清除浮动&内容居中&文字溢出
    网址大全
    any more
    下载网页视频
    下载无损音乐
    "前端" 宝藏网站
  • 原文地址:https://www.cnblogs.com/server126/p/1966525.html
Copyright © 2020-2023  润新知