您的问题似乎不完整,您是想询问关于C语言编程的某个具体问题吗?比如C语言的语法、编程技巧、项目开发等。请提供更具体的信息,这样我才能给出更准确的回答。
- 内容介绍
- 文章标签
- 相关推荐
本文共计362个文字,预计阅读时间需要2分钟。
拖放操作是我比较喜欢的用户体验,但实现起来略显繁琐。以下是一个简单的集合,包含了一些常用的拖放扩展方法,便于快速调用:
javastatic class DrapDropExtend { public static void SimpleDrag() { // 简单拖放实现代码 }}
拖放操作是一个我比较喜欢的用户体验,但实现起来稍显麻烦,这里我将它的常用方式简单的集合了一下,作为扩展方法,以便快速调用:
static class DrapDropExtend { public static void SimpleDrapDrop<T>(this Control c, string dataformat, Action<T> hanlder) where T : class { c.AllowDrop = true; c.DragEnter += (s, e) => { if (e.Data.GetDataPresent(dataformat)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; }; c.DragDrop += (s, e) => { var data = e.Data.GetData(dataformat) as T; hanlder(data); }; } public static void SimpleDrapDrop(this Control c, Action<DragEventArgs> enterHanlder, Action<DragEventArgs> dropHanlder) { c.AllowDrop = true; c.DragEnter += (s, e) => enterHanlder(e); c.DragDrop += (s, e) => enterHanlder(e); } public static void SimpleDrapDrop(this Control c, DragEventHandler enterHanlder, DragEventHandler dropHanlder) { c.AllowDrop = true; c.DragEnter += enterHanlder; c.DragDrop += dropHanlder; } }
该类使得实现拖放更加简单了,一个简单的示例如下:
public Form1() { InitializeComponent(); this.SimpleDrapDrop<string>(DataFormats.Text, x => this.Text = x); }
这比通过IDE来实现要简洁得多。
到此这篇关于C#快速实现拖放操作的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持自由互联。
本文共计362个文字,预计阅读时间需要2分钟。
拖放操作是我比较喜欢的用户体验,但实现起来略显繁琐。以下是一个简单的集合,包含了一些常用的拖放扩展方法,便于快速调用:
javastatic class DrapDropExtend { public static void SimpleDrag() { // 简单拖放实现代码 }}
拖放操作是一个我比较喜欢的用户体验,但实现起来稍显麻烦,这里我将它的常用方式简单的集合了一下,作为扩展方法,以便快速调用:
static class DrapDropExtend { public static void SimpleDrapDrop<T>(this Control c, string dataformat, Action<T> hanlder) where T : class { c.AllowDrop = true; c.DragEnter += (s, e) => { if (e.Data.GetDataPresent(dataformat)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; }; c.DragDrop += (s, e) => { var data = e.Data.GetData(dataformat) as T; hanlder(data); }; } public static void SimpleDrapDrop(this Control c, Action<DragEventArgs> enterHanlder, Action<DragEventArgs> dropHanlder) { c.AllowDrop = true; c.DragEnter += (s, e) => enterHanlder(e); c.DragDrop += (s, e) => enterHanlder(e); } public static void SimpleDrapDrop(this Control c, DragEventHandler enterHanlder, DragEventHandler dropHanlder) { c.AllowDrop = true; c.DragEnter += enterHanlder; c.DragDrop += dropHanlder; } }
该类使得实现拖放更加简单了,一个简单的示例如下:
public Form1() { InitializeComponent(); this.SimpleDrapDrop<string>(DataFormats.Text, x => this.Text = x); }
这比通过IDE来实现要简洁得多。
到此这篇关于C#快速实现拖放操作的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持自由互联。

