csharp beginer put the code to my pro ject

How can i put this code into my project
I get the code form web http://www.java2s.com/Tutorial/CSharp/0460__GUI-Windows-Forms/DragandDropTextBox.htm





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(28, 129);
        this.TextBox2.Multiline = true;
        this.TextBox2.Size = new System.Drawing.Size(196, 77);
        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(28, 36);
        this.TextBox1.Multiline = true;
        this.TextBox1.Size = new System.Drawing.Size(196, 77);
        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(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.Add(this.TextBox2);
        this.Controls.Add(this.TextBox1);
        this.ResumeLayout(false);
        this.PerformLayout();

    }
}
/* this is the code that it create for me auto matic how can i put the code above to my code */
 
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
 
 
 
using System.Text;
using System.Windows.Forms;
 
namespace CdLibraryOneRow
{
    public partial class datainsert : Form
    {
        public datainsert()
        {
            InitializeComponent();
        }
 
        private void datainsert_Load(object sender, EventArgs e)
        {
 
 
 
        }

Open in new window

teeraAsked:
Who is Participating?
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
In your Form1.Desginer.cs: Delete
#region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // datainsert
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "datainsert";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.datainsert_Load);
            this.ResumeLayout(false);
        }
        #endregion

And also Delete : Program.cs and paste below code in you  Form1.cs

using System;
using System.Drawing;
using System.Windows.Forms;
 
namespace CdLibraryOneRow
{
    public partial class datainsert : Form
    {
        private TextBox TextBox1;
        private TextBox TextBox2;
 
        public datainsert()
        {
            InitializeComponent();
        }
 
        [STAThread]
        public static void Main(string[] args)
        {
            Application.Run(new datainsert());
        }
 
        private void InitializeComponent()
        {
            TextBox2 = new TextBox();
            TextBox1 = new TextBox();
            SuspendLayout();
 
            TextBox2.AllowDrop = true;
            TextBox2.Location = new Point(28, 129);
            TextBox2.Multiline = true;
            TextBox2.Size = new Size(196, 77);
            TextBox2.DragDrop += TextBox_DragDrop;
            TextBox2.DragEnter += TextBox_DragEnter;
            TextBox2.MouseDown += TextBox_MouseDown;
 
            TextBox1.AllowDrop = true;
            TextBox1.Location = new Point(28, 36);
            TextBox1.Multiline = true;
            TextBox1.Size = new Size(196, 77);
            TextBox1.DragDrop += TextBox_DragDrop;
            TextBox1.DragEnter += TextBox_DragEnter;
            TextBox1.MouseDown += TextBox_MouseDown;
 
            AutoScaleDimensions = new SizeF(6F, 13F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(292, 266);
            Controls.Add(TextBox2);
            Controls.Add(TextBox1);
            ResumeLayout(false);
            PerformLayout();
        }
 
        private static void TextBox_MouseDown(object sender, MouseEventArgs e)
        {
            var txt = (TextBox) sender;
            txt.SelectAll();
            txt.DoDragDrop(txt.Text, DragDropEffects.Copy);
        }
 
        private static void TextBox_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.Data.GetDataPresent(DataFormats.Text) ? DragDropEffects.Copy : DragDropEffects.None;
        }
 
        private static void TextBox_DragDrop(object sender, DragEventArgs e)
        {
            var txt = (TextBox) sender;
            txt.Text = (string) e.Data.GetData(DataFormats.Text);
        }
 
 
        private void datainsert_Load(object sender, EventArgs e)
        {
        }
    }
}

Open in new window

0
 
Nirmalan NagenthiranCommented:
Create a Windows Application (I guess in VSS 2008)

By default Form1 added.

Under Form1.cs paste the following piece of code

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);
        }



Now open  Form1.designer.cs paste the following piece of code

  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(28, 129);
            this.TextBox2.Multiline = true;
            this.TextBox2.Size = new System.Drawing.Size(196, 77);
            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(28, 36);
            this.TextBox1.Multiline = true;
            this.TextBox1.Size = new System.Drawing.Size(196, 77);
            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(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.TextBox2);
            this.Controls.Add(this.TextBox1);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

Build it and run the application :)


0
 
teeraAuthor Commented:
Hi  sree_ven

it work
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
Need further guidance on this ? If not can you close this thread by you acceptance. Thanks
0
 
teeraAuthor Commented:
Hi NNirmalan  I  try   How can i correct it please suggest

Error      1      The call is ambiguous between the following methods or properties: 'WindowsFormsApplication1.Form1.InitializeComponent()' and 'WindowsFormsApplication1.Form1.InitializeComponent()'      C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\WindowsFormsApplication1\Form1.cs      16      13      WindowsFormsApplication1



This is the Form1.designer.cs

namespace WindowsFormsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        #endregion



        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(28, 129);
            this.TextBox2.Multiline = true;
            this.TextBox2.Size = new System.Drawing.Size(196, 77);
            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(28, 36);
            this.TextBox1.Multiline = true;
            this.TextBox1.Size = new System.Drawing.Size(196, 77);
            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(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.TextBox2);
            this.Controls.Add(this.TextBox1);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
    }
}




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
 
        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);
        }
 
 
    }
}

Open in new window

0
 
Sreedhar VengalaSr. Consultant - Business IntelligenceCommented:
Delete this:
  private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }
0
 
Nirmalan NagenthiranCommented:
Remove

private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.