clipboard pastes two times
-
i want to copy a tex from texbox and paste it another one in my form i copy it with that code
Clipboard.SetText(textBox1.SelectedText);
and paste it with that
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
textBox2.Text = Clipboard.GetText();
}but the problem is it pastes selceted text two times but when i try like that
(e.Modifiers == Keys.Control)
it pastes one time what should i do now ?
-
i want to copy a tex from texbox and paste it another one in my form i copy it with that code
Clipboard.SetText(textBox1.SelectedText);
and paste it with that
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
textBox2.Text = Clipboard.GetText();
}but the problem is it pastes selceted text two times but when i try like that
(e.Modifiers == Keys.Control)
it pastes one time what should i do now ?
-
I've tested your code and it is working fine for me. I think that the problem must be somewhere else. What is the content of the Clipboard when pasting?
its content is te selected text from the textbox..for example if i write 'w' in my textbox and paste it to my another box it appears 'ww'
-
its content is te selected text from the textbox..for example if i write 'w' in my textbox and paste it to my another box it appears 'ww'
hey friend thanks for reply..i solved my problem ..i set my form's KeyPreview false and it works now..
-
hey friend thanks for reply..i solved my problem ..i set my form's KeyPreview false and it works now..
-
hey friend thanks for reply..i solved my problem ..i set my form's KeyPreview false and it works now..
CTRL/V is handled automatically by some Controls. You make the Form react to it, but didn't tell the system that is all you want to happen, so if a suitable Control has focus, it will still oblige the CTRL/V. Clearing KeyPreview is unlikely the solution; it was set for a reason. Look for KeyEventArgs.Handled and SuppressKeyPress. :)
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.
-
i want to copy a tex from texbox and paste it another one in my form i copy it with that code
Clipboard.SetText(textBox1.SelectedText);
and paste it with that
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control)&&(e.KeyCode == Keys.V))
textBox2.Text = Clipboard.GetText();
}but the problem is it pastes selceted text two times but when i try like that
(e.Modifiers == Keys.Control)
it pastes one time what should i do now ?
I believe you want to handle an event for the control you're pasting into as opposed to handling it in the form.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
I believe you want to handle an event for the control you're pasting into as opposed to handling it in the form.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997i have 17 textboxes on my form and i want the user can copy from one box and paste to another...that is why i did so
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.V))
{
foreach (Control item in this.Controls)
{
if (item.GetType().Name == "TextBox")
if (item.Enabled)
item.Text = Clipboard.GetText();
}
}
}it works well..but after i saw your replies i wonder if there is better way or i am in wrong way ?
-
i have 17 textboxes on my form and i want the user can copy from one box and paste to another...that is why i did so
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.V))
{
foreach (Control item in this.Controls)
{
if (item.GetType().Name == "TextBox")
if (item.Enabled)
item.Text = Clipboard.GetText();
}
}
}it works well..but after i saw your replies i wonder if there is better way or i am in wrong way ?
I found this on google (search phrase is "c# textbox events"): http://www.vcskicks.com/clipboard-textbox.php[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997 -
i have 17 textboxes on my form and i want the user can copy from one box and paste to another...that is why i did so
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.V))
{
foreach (Control item in this.Controls)
{
if (item.GetType().Name == "TextBox")
if (item.Enabled)
item.Text = Clipboard.GetText();
}
}
}it works well..but after i saw your replies i wonder if there is better way or i am in wrong way ?
You shoulnd't have to do anything at all. The TextBox already supports Copy/Paste on its own without any code from you.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak