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;
            }
        }
    }
  • 相关阅读:
    beta冲刺1
    凡事预则立-于Beta冲刺前
    SDN第二次作业
    事后诸葛亮(团队)
    SDN第一次上机作业
    冲刺总结随笔
    Alpha第三天
    Alpha第二天
    Alpha冲刺博客集
    项目需求分析(团队)
  • 原文地址:https://www.cnblogs.com/hdl217/p/2117072.html
Copyright © 2011-2022 走看看