-
c#拖放技术的典型应用
在应用程序中,有时用户希望将数据从一个控件中拖到另一个控件中,此时就需要用到拖放技术。
程序开发步骤:
(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 | DragDropEffects.Link);
} }