以前做过一个,但现在代码不在身边!
可以给你一些见意!
托动的无非也是控件,而从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;
   }
}
查查帮肋就知道了

解决方案 »

  1.   

    下面代码是个示例,你试试看行不行:private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      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;
     }
      

  2.   

    你可以这样实现:
    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);
    }