像这样的效果在windows窗体里怎么实现,
例:比如想把QQ快捷方式放到statusStrip里,可如何获取正在拖动QQ快捷方式的属性,并且怎么加入效果如何实现。请不希赐教

解决方案 »

  1.   


    using   System;   
      using   System.Drawing;   
      using   System.Collections;   
      using   System.ComponentModel;   
      using   System.Windows.Forms;   
      using   System.Data;   
      using   System.Diagnostics;   
        
      namespace   拖拽成按钮   
      {   
      ///   <summary>   
      ///   Form1   的摘要说明。   
      ///   </summary>   
      public   class   Form1   :   System.Windows.Forms.Form   
      {   
      ///   <summary>   
      ///   必需的设计器变量。   
      ///   </summary>   
      private   System.ComponentModel.Container   components   =   null;   
        
      public   Form1()   
      {   
      //   
      //   Windows   窗体设计器支持所必需的   
      //   
      InitializeComponent();   
        
      //   
      //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码   
      //   
      }   
        
      ///   <summary>   
      ///   清理所有正在使用的资源。   
      ///   </summary>   
      protected   override   void   Dispose(   bool   disposing   )   
      {   
      if(   disposing   )   
      {   
      if   (components   !=   null)     
      {   
      components.Dispose();   
      }   
      }   
      base.Dispose(   disposing   );   
      }   
        
      #region   Windows   窗体设计器生成的代码   
      ///   <summary>   
      ///   设计器支持所需的方法   -   不要使用代码编辑器修改   
      ///   此方法的内容。   
      ///   </summary>   
      private   void   InitializeComponent()   
      {   
      //     
      //   Form1   
      //     
      this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);   
      this.ClientSize   =   new   System.Drawing.Size(352,   285);   
      this.Name   =   "Form1";   
      this.Text   =   "Form1";   
      this.Load   +=   new   System.EventHandler(this.Form1_Load);   
      this.DragDrop   +=   new   System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);   
      this.DragEnter   +=   new   System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);   
        
      }   
      #endregion   
        
      ///   <summary>   
      ///   应用程序的主入口点。   
      ///   </summary>   
      [STAThread]   
      static   void   Main()     
      {   
      Application.Run(new   Form1());   
      }   
        
      private   void   Form1_Load(object   sender,   System.EventArgs   e)   
      {   
      this.AllowDrop   =   true;   
      this.p   =   new   Point(1,1);   
      }   
      ///   <summary>   
      ///   文件路径   
      ///   </summary>   
      string     strFileName;   
      ///   <summary>   
      ///   btn的起始位置   
      ///   </summary>   
      Point   p;   
      //托拽文件或快捷方式进入窗体是记录它的路径   
      private   void   Form1_DragEnter(object   sender,   System.Windows.Forms.DragEventArgs   e)   
      {   
      e.Effect   =   DragDropEffects.Copy;   
      String[]   str_Drop=(String[])e.Data.GetData(DataFormats.FileDrop,true);   
      this.strFileName   =   str_Drop[0];   
      }   
      //推拽释放时生成按钮   
      private   void   Form1_DragDrop(object   sender,   System.Windows.Forms.DragEventArgs   e)   
      {   
      Button   btn   =   new   Button();   
      //保存文件的路径   
      btn.Tag   =   this.strFileName;   
      btn.Text   =this.strFileName.Substring(this.strFileName.LastIndexOf(@"\"));   
      btn.Click   +=new   EventHandler(btn_Click);   
      btn.Location   =   this.p;   
      this.p.X   +=   100;   
      if(this.p.X   >   this.Width)   
      {   
      this.p.X   =   1;   
      this.p.Y   +=   30;   
      }   
      this.Controls.Add(btn);   
        
        
      }   
      private   void   btn_Click(object   sender,   System.EventArgs   e)   
      {   
      ProcessStartInfo   Info=new   ProcessStartInfo();   
      try   
      {   
      Info.FileName   =   ((Button)sender).Tag.ToString();   
      Process.Start(Info);   
      }   
      catch(Win32Exception   win32ex)   
        
      {   
      MessageBox.Show("出错原因:"+win32ex.Message,"出错",MessageBoxButtons.OK,MessageBoxIcon.Error);   
      }   
      }                             
      }   
      }   
      

  2.   

    vs2005版:
    我已经测过.你自己去试试吧using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics; namespace WindowsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        ///   <summary>   
            ///   文件路径   
            ///   </summary>   
            string strFileName;
            ///   <summary>   
            ///   btn的起始位置   
            ///   </summary>   
            Point p;
                     //推拽释放时生成按钮
            private void Form2_DragDrop(object sender, DragEventArgs e)
            {
                Button btn = new Button();
                //保存文件的路径   
                btn.Tag = this.strFileName;
                btn.Text = this.strFileName.Substring(this.strFileName.LastIndexOf(@"\"));
                btn.Click += new EventHandler(btn_Click);
                btn.Location = this.p;
                this.p.X += 100;
                if (this.p.X > this.Width)
                {
                    this.p.X = 1;
                    this.p.Y += 30;
                }
                this.Controls.Add(btn);           }        //托拽文件或快捷方式进入窗体是记录它的路径  
            private void Form2_DragEnter(object sender, DragEventArgs e)
            {
                e.Effect = DragDropEffects.Copy;
                String[] str_Drop = (String[])e.Data.GetData(DataFormats.FileDrop, true);
                this.strFileName = str_Drop[0];   
            }        private void Form2_Load(object sender, EventArgs e)
            {
                this.AllowDrop = true;
                this.p = new Point(1, 1);   
            }        private void btn_Click(object sender, EventArgs e)
            {
                ProcessStartInfo Info = new ProcessStartInfo();
                try
                {
                    Info.FileName = ((Button)sender).Tag.ToString();
                    Process.Start(Info);
                }
                catch (Win32Exception win32ex)
                {
                    MessageBox.Show("出错原因:" + win32ex.Message, "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }           }
        }
    }
      

  3.   

    to:潇湘夜雨
    大部分好用,可我的电脑,我的文档,IE它们拖上去并不好用,
    这个可以解决吗?