Drag and Drop TextBox : Drag Drop « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Drag Drop 
23.59.1.Drag and Drop TextBox
Drag and Drop TextBox
using System;
using System.Windows.Forms;

public class TextBoxDragDropDemo : Form
{
    public TextBoxDragDropDemo()
    {
        InitializeComponent();
    }

    private void TextBox_MouseDown(object sender, MouseEventArgs e)
    {
        TextBox txt = (TextBox)sender;
        txt.SelectAll();
        txt.DoDragDrop(txt.Text, DragDropEffects.Copy);
    }

    private void TextBox_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.Text))
        {
            e.Effect = DragDropEffects.Copy;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }

    private void TextBox_DragDrop(object sender, DragEventArgs e)
    {
        TextBox txt = (TextBox)sender;
        txt.Text = (string)e.Data.GetData(DataFormats.Text);
    }

    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new TextBoxDragDropDemo());
    }
    private System.Windows.Forms.TextBox TextBox2;
    private System.Windows.Forms.TextBox TextBox1;

    private void InitializeComponent()
    {
        this.TextBox2 = new System.Windows.Forms.TextBox();
        this.TextBox1 = new System.Windows.Forms.TextBox();
        this.SuspendLayout();

        this.TextBox2.AllowDrop = true;
        this.TextBox2.Location = new System.Drawing.Point(28129);
        this.TextBox2.Multiline = true;
        this.TextBox2.Size = new System.Drawing.Size(19677);
        this.TextBox2.DragDrop += new System.Windows.Forms.DragEventHandler(this.TextBox_DragDrop);
        this.TextBox2.DragEnter += new System.Windows.Forms.DragEventHandler(this.TextBox_DragEnter);
        this.TextBox2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextBox_MouseDown);

        this.TextBox1.AllowDrop = true;
        this.TextBox1.Location = new System.Drawing.Point(2836);
        this.TextBox1.Multiline = true;
        this.TextBox1.Size = new System.Drawing.Size(19677);
        this.TextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.TextBox_DragDrop);
        this.TextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.TextBox_DragEnter);
        this.TextBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextBox_MouseDown);

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292266);
        this.Controls.Add(this.TextBox2);
        this.Controls.Add(this.TextBox1);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
}
23.59.Drag Drop
23.59.1.Drag and Drop TextBoxDrag and Drop TextBox
23.59.2.File Drop Target
23.59.3.Drag Drop Sample
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.