首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# DragDrop来自toolStrip

C# DragDrop来自toolStrip
EN

Stack Overflow用户
提问于 2013-03-12 14:39:50
回答 1查看 2.3K关注 0票数 3

我正在寻找一种方法来确定在发生toolStrip事件后被拖动的DragDrop中的哪一项,我所要做的就是为工具箱中的每一项设置不同的情况,但我似乎找不到比较它们的方法。

更新:短CODESAMPLE

代码语言:javascript
复制
private void toolStrip1_DragDrop(object sender, DragEventArgs e)
{
    //Here I want something like a DoDragDrop() and send the specific item from the
    //toolstrip..
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
    //And here some way to determine which of the items was dragged 
    //(I'm not completely sure if I need a mouseUp event though..)
}

希望能更容易地得到我想做的事。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-12 15:55:49

示例中的事件看起来不像要使用的正确事件。

下面是一个包含2个ToolStrip的ToolStripButtons的工作示例:

代码语言:javascript
复制
public Form1() {
  InitializeComponent();
  toolStripButton1.MouseDown += toolStripButton_MouseDown;
  toolStripButton2.MouseDown += toolStripButton_MouseDown;

  panel1.DragEnter += panel1_DragEnter;
  panel1.DragDrop += panel1_DragDrop;
}

void toolStripButton_MouseDown(object sender, MouseEventArgs e) {
  this.DoDragDrop(sender, DragDropEffects.Copy);
}

void panel1_DragEnter(object sender, DragEventArgs e) {
  e.Effect = DragDropEffects.Copy;
}

void panel1_DragDrop(object sender, DragEventArgs e) {
  ToolStripButton button = e.Data.GetData(typeof(ToolStripButton))
                           as ToolStripButton;
  if (button != null) {
    if (button.Equals(toolStripButton1)) {
      MessageBox.Show("Dragged and dropped Button 1");
    } else if (button.Equals(toolStripButton2)) {
      MessageBox.Show("Dragged and dropped Button 2");
    }
  }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15364264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档