• 4.Winform实现控件拖动


    *记得更改下方Panel的属性

        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            Button btn = null;
            private void button1_MouseDown(object sender, MouseEventArgs e)
            {
    
            }
    
            private void panel2_DragEnter(object sender, DragEventArgs e)
            {
    
                if (e.Data.GetDataPresent(typeof(Button)))
                {
                    e.Effect = DragDropEffects.Move;
                }
                (sender as Panel).BackgroundImage = Properties.Resources._1;
            }
    
            private void panel2_DragDrop(object sender, DragEventArgs e)
            {
    
                int x = (sender as Panel).Location.X + 2;
                int y = (sender as Panel).Location.Y + 2;
    
                btn = e.Data.GetData(typeof(Button)) as Button;
    
                // btn.Location = this.PointToClient(new Point(e.X - btn.Width / 2, e.Y - btn.Height / 2));
                //btn.Location = this.PointToClient(new Point(x, y));
                btn.Location = new Point(x, y);
                //MessageBox.Show(x.ToString()+":"+y.ToString()+"");
                (sender as Panel).BackgroundImage = null;
            }
    
            private void panel2_DragLeave(object sender, EventArgs e)
            {
                (sender as Panel).BackgroundImage = null;
            }
    
    
            private void panel2_MouseEnter(object sender, EventArgs e)
            {
                (sender as Panel).BackgroundImage = Properties.Resources._1;
            }
    
            private void panel2_MouseLeave(object sender, EventArgs e)
            {
                (sender as Panel).BackgroundImage = null;
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
    
            }
    
    
            private void button1_MouseMove(object sender, MouseEventArgs e)
            {
    
                if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    (sender as Button).DoDragDrop(sender as Button, DragDropEffects.Move);
                }
            }
    
            private void button5_Click_1(object sender, EventArgs e)
            {
                MessageBox.Show((sender as Button).Text);
    
            }
    
    
    
    
            private void panel10_DragEnter(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(typeof(Button)))
                {
                    e.Effect = DragDropEffects.Move;
                }
                (sender as Panel).BackgroundImage = Properties.Resources._3;
            }
            private Button btn2 = null;
            private void panel10_DragDrop(object sender, DragEventArgs e)
            {
    
                int x = (sender as Panel).Location.X + 2;
                int y = (sender as Panel).Location.Y + 2;
    
                btn2 = e.Data.GetData(typeof(Button)) as Button;
                btn2.Location = new Point(x, y);
                (sender as Panel).BackgroundImage = null;
            }
    
            private void panel10_DragLeave(object sender, EventArgs e)
            {
                (sender as Panel).BackgroundImage = null;
            }
    
            private void panel10_MouseEnter(object sender, EventArgs e)
            {
                (sender as Panel).BackgroundImage = Properties.Resources._4;
            }
    
            private void panel10_MouseLeave(object sender, EventArgs e)
            {
    
                (sender as Panel).BackgroundImage = null;
            }
    
            private void btnkuGou_Click(object sender, EventArgs e)
            {
    
                Process p = new Process();
                p.StartInfo.FileName = @"D:Program FilesKuGouKGMusicKuGou.exe";
                p.Start();
    
            }
    
            //private void button6_Click(object sender, EventArgs e)
            //{
            //    //D:Program FilesKuGouKGMusic
            //    Process p = new Process();
            //    p.StartInfo.FileName = @"D:Program FilesKuGouKGMusicKuGou.exe";
            //    p.Start();
            //}
        }
  • 相关阅读:
    无线路由器wds桥接技术+丢包率
    2016CCPC东北地区大学生程序设计竞赛1008/HDU 5929 模拟
    Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心
    Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
    Codeforces Round #310 (Div. 2) A B C
    Codeforces Round #374 (Div. 2) A B C D 水 模拟 dp+dfs 优先队列
    Codeforces Round #313 (Div. 2) A B C 思路 枚举 数学
    Codeforces Round #373 (Div. 2) A B C 水 贪心 模拟(四舍五入进位)
    CentOS7 PostgreSQL 安装
    数据库事务的隔离级别
  • 原文地址:https://www.cnblogs.com/LifeForCode/p/3303574.html
Copyright © 2020-2023  润新知