一、窗体接收拖入数据
效果:将数据(文件)一拖动到窗体上面,就显示数据信息
1、设置:AllowDrop属性值为True
2、设置DragEnter事件属性
private void Form1_DragEnter(object sender, DragEventArgs e)
{
string[] ss = e.Data.GetData(e.Data.GetFormats()[5]) as string[];
for (int i = 0; i < ss.Length; i++)
{
label1.Text += ss[i].ToString()+"\r\n";
}
}
二、拖动窗体内容移动
效果:在窗体正文中,单击并能拖动窗体移动
//1、获取当前窗体位置
Point oldP;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
oldP = e.Location;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
//2、如果是按下鼠标左键,就获得当前座标位置
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Point newP = e.Location;
int x = newP.X - oldP.X + Location.X;
int y = newP.Y - oldP.Y + Location.Y;
newP.X = x;
newP.Y = y;
this.Location = newP;
}
}