以前做过一个,但现在代码不在身边!
可以给你一些见意!
托动的无非也是控件,而从Control继承过来的控件如
Button,Label..之类的控件都是支持拖放的
1>你得把他们的AllowDrop设为true就是允许控件接受拖放数据
//两个拖放的事件
2>private void Form1_DragDrop(object sender, DragEventArgs e)
3>private void Form1_DragEnter(object sender, DragEventArgs e)
private void Form1_DragDrop(object sender, DragEventArgs e)
{
// Handle FileDrop data.
if(e.Data.GetDataPresent(DataFormats.FileDrop) )
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the picture variable.
this.picture = Image.FromFile(files[0]);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
} // Handle Bitmap data.
if(e.Data.GetDataPresent(DataFormats.Bitmap) )
{
try
{
// Create an Image and assign it to the picture variable.
this.picture = (Image)e.Data.GetData(DataFormats.Bitmap);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
// Force the form to be redrawn with the image.
this.Invalidate();
}private void Form1_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file or a bitmap, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.Bitmap) ||
e.Data.GetDataPresent(DataFormats.FileDrop) )
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
查查帮肋就知道了
可以给你一些见意!
托动的无非也是控件,而从Control继承过来的控件如
Button,Label..之类的控件都是支持拖放的
1>你得把他们的AllowDrop设为true就是允许控件接受拖放数据
//两个拖放的事件
2>private void Form1_DragDrop(object sender, DragEventArgs e)
3>private void Form1_DragEnter(object sender, DragEventArgs e)
private void Form1_DragDrop(object sender, DragEventArgs e)
{
// Handle FileDrop data.
if(e.Data.GetDataPresent(DataFormats.FileDrop) )
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the picture variable.
this.picture = Image.FromFile(files[0]);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
} // Handle Bitmap data.
if(e.Data.GetDataPresent(DataFormats.Bitmap) )
{
try
{
// Create an Image and assign it to the picture variable.
this.picture = (Image)e.Data.GetData(DataFormats.Bitmap);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
// Force the form to be redrawn with the image.
this.Invalidate();
}private void Form1_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file or a bitmap, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.Bitmap) ||
e.Data.GetDataPresent(DataFormats.FileDrop) )
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
查查帮肋就知道了
解决方案 »
- 谁帮我讲讲C#的Weak Event概念,谢谢
- datagridview 的 anchor问题
- c#报表问题
- 求SQL语句
- 主窗体如何知道用户控件激发了哪个事件?
- 对页面级别和按钮级别都做到了,但数据级别的暂时没思路,谁能指点下,3q
- 在继承来的toolStrip控件中如何添加新的toolStripButton?
- 關于視頻網站建設問題
- c#+sqlserver2000开发一个小软件,给钱的……………… (ycxdy )
- MSIL是怎么回事?
- 请问怎样从不同数据源中获取想要的东西?(*.xls和Sql Server 2000)在线等待!
- 编译两个C#的CS文件其中两个文件中的类有调用关系,如何用命令进行编译(高手请指教)
{
if(e.Button == MouseButtons.Left){
Point mousePos = Control.MousePosition;
if(e.Y > 0 && e.Y < 20)
this.Location = new Point(mousePos.X - pt.X,mousePos.Y - pt.Y);
}
} Point pt = new Point(0);private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
pt.X = e.X;
pt.Y = e.Y;
}
using System.Runtime.InteropServices;[DllImport("user32.dll",EntryPoint="SendMessage")]
public static extern int SendMessage(int hWnd,int wMsg,int wParam,int lParam);
[DllImport("user32.dll",EntryPoint="ReleaseCapture")]
public static extern int ReleaseCapture();
public const int WM_SysCommand = 0x0112;
public const int SC_MOVE = 0xF012;private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle.ToInt32(),WM_SysCommand,SC_MOVE,0);
}