Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

csharp beginer  put the code to my pro ject

Posted on 2009-04-16
7
Medium Priority
?
211 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:teera
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Assisted Solution

by:Nirmalan Nagenthiran
Nirmalan Nagenthiran earned 600 total points
ID: 24155888
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
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 1400 total points
ID: 24155909
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
 

Author Comment

by:teera
ID: 24156220
Hi  sree_ven

it work
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24156246
Need further guidance on this ? If not can you close this thread by you acceptance. Thanks
0
 

Author Comment

by:teera
ID: 24156257
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
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24156269
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
 
LVL 12

Expert Comment

by:Nirmalan Nagenthiran
ID: 24156289
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question