zoukankan      html  css  js  c++  java
  • CS 拖动窗体控件代码

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            bool tuodong = false;//全局变量用于控制是否开始拖动 
            //按钮的MouseDown事件 
            private void button3_MouseDown(object sender, MouseEventArgs e)
            {
                Point p = this.PointToClient(Cursor.Position);
                button3.Location = new Point(p.X - button3.Width / 2, p.Y - button3.Height / 2);
                tuodong = true;
            }
            //按钮的MouseMove事件 
            private void button3_MouseMove(object sender, MouseEventArgs e)
            {
                if (tuodong)
                {
                    Point p = this.PointToClient(Cursor.Position);
                    button3.Location = new Point(p.X - button3.Width / 2, p.Y - button3.Height / 2);
                }
            }
            //按钮的MouseUp事件 
            private void button3_MouseUp(object sender, MouseEventArgs e)
            {
                tuodong = false;
            }
        }
    }
  • 相关阅读:
    bzoj1001 狼抓兔子
    bzoj1015 星球大战
    noip模拟赛 楼
    noip模拟赛 radius
    noip模拟赛 helloworld
    noip模拟赛 hungary
    noip模拟赛 gcd
    洛谷P3375【模板】KMP字符串匹配
    noip模拟赛 隔壁
    noip模拟赛 对刚
  • 原文地址:https://www.cnblogs.com/hdl217/p/2117072.html
Copyright © 2011-2022 走看看