DragDrop事件 [英] DragDrop Event

查看:108
本文介绍了DragDrop事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个窗口项目,其中我采用了一种形式,而我采用了一个面板.
现在故事开始了...
当我从桌面上选择一个文件并将其拖动到面板上时,我想要一些消息框提示,例如"XYZ文件被拖放到面板上" ...我该怎么做????我的代码是C#.NET. :doh:

Hi all,

I have a window project in which i took one form and in that i took one panel.
Now story begins......
I want some message box prompt e.g "XYZ file is drag-dropped to the panel" when i select one file from my desktop and dragged it to the panel...How can i do that?????? my code is C#.NET. :doh:

推荐答案

查看本文:

在C#.NET中拖放图像 [ http://www .google.co.uk/search?hl = zh-CN& q = drag + file + to + window +%2B + c%23.net& meta = [
Check out this article:

Drag and Drop Image in C#.NET[^]

It''s for images but I''m sure you can adapt it to meet your requirements.

Also Google gives you many hits:

http://www.google.co.uk/search?hl=en&q=drag+file+to+window+%2B+c%23.net&meta=[^]




1.将Panel的以下属性设置为True(如果设置为false)
"AllowDrop"
2.然后,您应该为两个事件编写事件处理程序.一种是DragEnter和DragDrop. (a)DragEnter决定将要拖动的数据是否为有效数据,如果有效数据,则(b)DragDrop允许将要拖动到其上的数据.

因此,DragEnter的事件处理程序应用于检查数据,并在DragDrop中编写代码以在数据接受后对其进行处理.


Hi,

1. Set following property for Panel to True (if it was set to false)
"AllowDrop"
2. Then there are two events for which you that you should write event handler. One is DragEnter and DragDrop. (a) DragEnter decides whether data going to be draged is valid data and if valid data then (b)DragDrop accets the data dragged onto it.

Therefore eventhandler of DragEnter should be for checking data and in DragDrop you write your code to process data after it is accepted.


private void panel1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect = DragDropEffects.Copy; // Okay
            else
                e.Effect = DragDropEffects.None; // Unknown data, ignore it

        }





private void panel1_DragDrop(object sender, DragEventArgs e)
        {
            MessageBox.Show("XYZ file is drag-dropped to the panel");
        }






希望对您有帮助






Hope that helps you,


这篇关于DragDrop事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆