使用复制粘贴按钮将选定文本从textbox1复制到vb.net或c#.net中的textbox2 [英] Copy Selected text from textbox1 to textbox2 in vb.net or c#.net using copy paste button

查看:68
本文介绍了使用复制粘贴按钮将选定文本从textbox1复制到vb.net或c#.net中的textbox2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows应用程序,textbox1和textbox2中有2个多行文本框。我有两个文本框的数据。我还在表单上有复制和粘贴按钮。

如果我选择textbox1选择的数据并单击复制按钮...那么它应该复制所选的数据,现在我转到下一个文本框textbox2并单击粘贴。然后它应该粘贴从textbox1中选择的数据。

以同样的方式将textbox2复制到textbox1数据并粘贴....

请建议.....

I have 2 multiline textboxes in windows application, textbox1 and textbox2. I have data on both textboxes. I also have copy and paste button on form.
If i select textbox1 selected data and clicks on copy button ...then it should copy data that is selected and now i goto next textbox textbox2 and click on "paste".then it should paste the data that was selected from textbox1.
And in the same way for textbox2 to textbox1 data should be copied and paste....
Please suggest.....

推荐答案

有几种方法可以做到这一点:

1)你可以使用实际的Windows剪贴板: Clipboard.GetText [ ^ ]和 Clipboard.SetText [ ^ ]是最简单的方法。



2您可以创建一个类级别的字符串变量来保存信息。这很简单,只需复制文本。如果您不想打扰其他应用程序的实际剪贴板内容,请使用此方法。



无论哪种方式,你只需要使用TextBox.SelectedText属性读取数据,并将其设置在另一个TB中,或者设置TextBox.Text属性如果你想要它替换所有文本。
There are a couple of ways you can do this:
1) You could use the actual windows clipboard: Clipboard.GetText[^] and Clipboard.SetText[^] are the easiest way to do it.
Or
2) You could create a class level string variable to hold the information. This is pretty easy, just copy the text in and out. Use this way if you don''t want to disturb the actual clipboard content for other applications.

Either way, you just need to read the data out using the TextBox.SelectedText property and either set it it in the other TB, or set the TextBox.Text property if you want it to replace all the text.


这篇关于使用复制粘贴按钮将选定文本从textbox1复制到vb.net或c#.net中的textbox2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆