CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

问什么我的textbox不能dragdrop,而dragover和dragenter都可以,allowdrop=true已经打开了 (没分了)

楼主2004831(纪念这一天[买盘找我])2004-11-01 22:04:43 在 .NET技术 / C# 提问

问什么我的textbox不能dragdrop,而dragover和dragenter都可以,allowdrop=true已经打开了    
   
  private   void   textBox1_DragDrop(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  MessageBox.Show("a");  
   
  }  
  label也一样不行  
   
  private   void   label1_DragDrop(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  MessageBox.Show("a");  
  }  
   
  可是DragOver和DragEnter就可以,怎么回事啊。有没有高手帮帮我啊。  
  问题点数:80、回复次数:7Top

1 楼hujiiori(Coder×Coder——sytu)回复于 2004-11-02 19:52:00 得分 0

DoDragDrop这个方法执行了没有?Top

2 楼xiaoslong(龙哥)回复于 2004-11-02 19:55:55 得分 0

帮你顶Top

3 楼2004831(纪念这一天[买盘找我])回复于 2004-11-02 21:14:19 得分 0

我是从资源管理器中拖一个文件过来Top

4 楼cnhgj(戏子) (没时间练太极)回复于 2004-11-06 14:38:55 得分 0

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
   
  namespace   TreeDnD  
  {  
  ///   <summary>  
  ///   Summary   description   for   Form1.  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.TextBox   textBox1;  
  ///   <summary>  
  ///   Required   designer   variable.  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form1()  
  {  
  //  
  //   Required   for   Windows   Form   Designer   support  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   Add   any   constructor   code   after   InitializeComponent   call  
  //  
  }  
   
  ///   <summary>  
  ///   Clean   up   any   resources   being   used.  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   Form   Designer   generated   code  
  ///   <summary>  
  ///   Required   method   for   Designer   support   -   do   not   modify  
  ///   the   contents   of   this   method   with   the   code   editor.  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  this.textBox1   =   new   System.Windows.Forms.TextBox();  
  this.SuspendLayout();  
  //    
  //   textBox1  
  //    
  this.textBox1.Location   =   new   System.Drawing.Point(72,   152);  
  this.textBox1.Name   =   "textBox1";  
  this.textBox1.Size   =   new   System.Drawing.Size(280,   21);  
  this.textBox1.TabIndex   =   2;  
  this.textBox1.Text   =   "textBox1";  
  //    
  //   Form1  
  //    
  this.AllowDrop   =   true;  
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(496,   341);  
  this.Controls.Add(this.textBox1);  
  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);  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   The   main   entry   point   for   the   application.  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
  private   void   Form1_DragEnter(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  if   (e.Data.GetDataPresent(DataFormats.FileDrop))    
  e.Effect   =   DragDropEffects.Copy;  
  else  
  e.Effect   =   DragDropEffects.None;  
  }  
   
  private   void   Form1_DragDrop(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  System.Array   myarr   =(System.Array)   e.Data.GetData(DataFormats.FileDrop);  
  System.Collections.IEnumerator   myEnumerator   =   myarr.GetEnumerator();  
  myEnumerator.MoveNext()   ;  
  textBox1.Text=myEnumerator.Current.ToString()   ;  
   
  }  
   
  private   void   Form1_Load(object   sender,   System.EventArgs   e)  
  {  
   
  }  
   
   
  }  
  }  
  Top

5 楼cnhgj(戏子) (没时间练太极)回复于 2004-11-06 14:40:09 得分 0

以上示例是拖动一个文件后,在TEXTBOX中显示该文件的路径的例子。。  
   
  把FORM1的AllowDrop设为true  
   
  private   void   Form1_DragEnter(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  if   (e.Data.GetDataPresent(DataFormats.FileDrop))    
  e.Effect   =   DragDropEffects.Copy;  
  else  
  e.Effect   =   DragDropEffects.None;  
  }  
   
  private   void   Form1_DragDrop(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  System.Array   myarr   =(System.Array)   e.Data.GetData(DataFormats.FileDrop);  
  System.Collections.IEnumerator   myEnumerator   =   myarr.GetEnumerator();  
  myEnumerator.MoveNext()   ;  
  textBox1.Text=myEnumerator.Current.ToString()   ;  
   
  }  
  Top

6 楼2004831(纪念这一天[买盘找我])回复于 2004-11-06 14:49:49 得分 0

我试了,没有用你的代码,我自己弄了一个Form1_DragEnter  
  把FORM1的AllowDrop设为true,可是就是不行,鼠标的形状也没有变化,  
  是怎么会是啊  
  Top

7 楼cnhgj(戏子) (没时间练太极)回复于 2004-11-06 14:59:01 得分 80

你要写事件,鼠标才会变的  
   
  private   void   Form1_DragEnter(object   sender,   System.Windows.Forms.DragEventArgs   e)  
  {  
  if   (e.Data.GetDataPresent(DataFormats.FileDrop))    
  e.Effect   =   DragDropEffects.Copy;  
  else  
  e.Effect   =   DragDropEffects.None;  
  }Top

相关问题

  • textbox
  • 从一个Listbox 里拖拽 数据到 TextBox,为什么TextBox的DragDrop事件无法触发??
  • asp:textbox???????
  • textbox的使用
  • Textbox的问题
  • textBox 的DataBindings
  • TextBox的问题
  • 关于textbox
  • TextBox问题...
  • 关于textbox

关键词

  • dragenter
  • dragdrop
  • allowdrop
  • drageventargs
  • myenumerator
  • textbox
  • dragdropeffects
  • filedrop
  • dragover
  • dataformats

得分解答快速导航

  • 帖主:2004831
  • cnhgj

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo