All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
让Asp.NET的DataGrid可排序、可选择、可分页_[Asp.Net教程]
编写对SEO友好的ASP.NET程序_[Asp.Net教程]
再现C#导出Excel源码_.net资料_编程技术
异常:操作必须使用一个可更新的查询。_[Asp.Net教程]
图片地址防盗链,通过IHttpHandler实现_.net资料_编程技术
追踪ASP.NET代码里的bug_[Asp.Net教程]
如何制作圆角表格_[Html教程]
动态网页制作技术PHP常用的正则表达式_[PHP教程]
Asp.Net+Ajax,用户名检测_[Asp.Net教程]
2个ASP.NET小技巧_[Asp.Net教程]
Reading number is top 10 pictures
世界五大海盗
The cat shit
这才是真正的人体艺术1
美丽的少女1
Sora aoi mirror memorial classics5
So beauty, will let you spray blood2
The money of more than 100 countries and regions1
俄罗斯台球天后惊艳魅惑1
八个盛产美女的国家2
一万二一支的万珂,用得真心肉疼。
Download software ranking
Professional killers2 data package
Boxer vs Yellow5
Tram sex maniac 2 (H) rar bag16
Be there or be square
卡丁车单机版
linux安装大全
功夫熊猫2(上集)
Unix video tutorial4
Eclipse 4.2.2 For Win64
Tram sex maniac 2 (H) rar bag3
qq published in(发表于) 2014/7/11 9:27:39 Edit(编辑)
C#教程:拖放技术的典型应用实例

C#教程:拖放技术的典型应用实例

C#教程:拖放技术的典型应用实例|方法

拖放技术的典型应用

在应用程序中,用户有时希望将数据从一个控件中拖到另一个控件中,此时就需要用到拖放技术。图1和图2演示在两个文本框之间拖放数据。



图1 拖放前



图2 拖放后

程序开发步骤如下所示。

(1)新建一个窗体,在窗体中添加两个Label控件和两个TextBox控件,并将两个TextBox控件分别命名为txtDataTart和txtScoure。

(2)将txtDataTart文本框的AllowDrop属性设置为True。

(3)程序主要代码如下所示:

private void txtDataTart_DragDrop(object sender, DragEventArgs e)

{

txtDataTart.Text = e.Data.GetData(DataFormats.Text).ToString();

}

private void txtDataTart_DragEnter(object sender, DragEventArgs e)

{

e.Effect = DragDropEffects.Copy;

}

private void txtScoure_MouseMove(object sender, MouseEventArgs e)

{

if ((e.Button & MouseButtons.Left) == MouseButtons.Left)

{

string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,

Application.StartupPath.LastIndexOf("")).LastIndexOf(""));

reportPath += @"sl3293dwarro.cur";

MyNoDropCursor = new Cursor(reportPath);

DragDropEffects dropEffect = this.txtScoure.DoDragDrop(this.txtScoure.Text, DragDropEffects.Copy | Drag DropEffects.Link);

}

}

完整程序代码如下:

★ ★★★★frmDoDragDrop.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _2_01

{

public partial class frmDoDragDrop : Form

{

public frmDoDragDrop()

{

InitializeComponent();

}

private Cursor MyNoDropCursor;

private void txtDataTart_DragDrop(object sender, DragEventArgs e)

{

txtDataTart.Text = e.Data.GetData(DataFormats.Text).ToString();

}

private void txtDataTart_DragEnter(object sender, DragEventArgs e)

{

e.Effect = DragDropEffects.Copy;

}

private void txtScoure_MouseMove(object sender, MouseEventArgs e)

{

if ((e.Button & MouseButtons.Left) == MouseButtons.Left)

{

string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,

Application.StartupPath.LastIndexOf("")).LastIndexOf(""));

reportPath += @"3dwarro.cur";

MyNoDropCursor = new Cursor(reportPath);

DragDropEffects dropEffect = this.txtScoure.DoDragDrop(this.txtScoure.Text, DragDropEffects.Copy | DragDropEffects.Link);

}

}

private void txtDataTart_DragOver(object sender, DragEventArgs e)

{

this.Cursor = MyNoDropCursor;

}

private void frmDoDragDrop_Load(object sender, EventArgs e)

{

}

}

}

★ ★★★★frmDoDragDrop.designer.cs窗体设计文件完整程序代码★★★★★

namespace _2_01

{

partial class frmDoDragDrop

{

///



/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///


/// 如果应释放托管资源,为 true;否则为 false。

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

///


private void InitializeComponent()

{

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.txtScoure = new System.Windows.Forms.TextBox();

this.txtDataTart = new System.Windows.Forms.TextBox();

this.SuspendLayout();

//

// label1

//

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(26, 20);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(53, 12);


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.