using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
// 作者 : V : jbossjf
namespace FireAlarm.Run
{
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
{
private int count = 1;
public XtraForm1()
{
InitializeComponent();
DragDrop += Form1_DragDrop;
DragEnter += Form1_DragEnter;
}
private void XtraForm1_Load(object sender, EventArgs e)
{
this.AllowDrop = true;
}
private void Form1_DragEnter(System.Object sender, DragEventArgs e)
{
//当Button被拖拽到WinForm上时候,鼠标效果出现
// if ((e.Data.GetDataPresent(typeof(Button))))
{
e.Effect = DragDropEffects.Copy;
}
}
private void Form1_DragDrop(System.Object sender, DragEventArgs e)
{
//拖放完毕之后,自动生成新控件
Button btn = new Button();
btn.Size = simpleButton1.Size;
btn.Location = this.PointToClient(new Point(e.X, e.Y));
//用这个方法计算出客户端容器界面的X,Y坐标。否则直接使用X,Y是屏幕坐标
this.Controls.Add(btn);
btn.Text = "按钮" + count.ToString();
count = count + 1;
btn.BringToFront();//将控件放置所有控件最顶层
//btn.SendToBack();//将控件放置所有控件最底层
btn.MouseDown += new MouseEventHandler(lable_MouseDown);
btn.MouseUp += new MouseEventHandler(lable_MouseUp);
btn.MouseMove += new MouseEventHandler(lable_MouseMove);
}
//鼠标移动窗体移动
private bool isMouseDown = false;
private Point lableLocation; //lable的location
private Point mouseOffset; //鼠标的按下位置
private void lable_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isMouseDown = true;
lableLocation = ((Button)sender).Location;
mouseOffset = Control.DeviceXtraUserControl.MousePosition;
}
}
private void lable_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
private void lable_MouseMove(object sender, MouseEventArgs e)
{
int _x = 0;
int _y = 0;
if (isMouseDown)
{
Point pt = Control.DeviceXtraUserControl.MousePosition;
_x = mouseOffset.X - pt.X;
_y = mouseOffset.Y - pt.Y;
((Button)sender).Location = new Point(lableLocation.X - _x, lableLocation.Y - _y);
}
}
private void simpleButton1_MouseDown(object sender, MouseEventArgs e)
{
//左键的话,标志位为true(表示拖拽开始)
if ((e.Button == System.Windows.Forms.MouseButtons.Left))
{
simpleButton1.DoDragDrop(simpleButton1, DragDropEffects.Copy | DragDropEffects.Move);
//形成拖拽效果,移动+拷贝的组合效果
}
}
}
}
08-19
233
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-31
400
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
![](https://csdnimg.cn/release/blogv2/dist/components/img/blogType.png)
工业视觉二维码批量识别
12-31
439
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
![](https://csdnimg.cn/release/blogv2/dist/components/img/blogType.png)
工业视觉OCR字符识别
12-31
456
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-27
1046
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-17
894
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-10
206
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-01
3545
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-31
1336
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
![](https://csdnimg.cn/release/blogv2/dist/components/img/blogType.png)
uniapp 下拉框
10-15
5546
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)