zoukankan      html  css  js  c++  java
  • 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();
            //}
        }
  • 相关阅读:
    预处理器宏指令(Macro)
    汇编语言中macro的用法
    USB设备的VID与PID
    前端工具 | JS编译器Monaco使用教程
    vue + ts中的shimsvue.d.ts文件的作用,在ts中引入vueecharts等vue文件 TypeScript 导入 JSON Module resolveJsonModule
    Jenkins自动打包并部署到远程服务器
    如何获取设备的VID,PID?
    TypeScript装饰器(decorators)
    MACRO指令
    IE6左右边框断线现象
  • 原文地址:https://www.cnblogs.com/LifeForCode/p/3303574.html
Copyright © 2011-2022 走看看