复制文本框的文本 [英] copy texts of a textbox

查看:117
本文介绍了复制文本框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想复制文本框的选定部分或整个文本,所以:
1.如何复制文本框的文本?并且可以直接从C#打印一些文本吗?


I want to copy selected part of a textbox or maybe whole of it, so:
1. How to copy texts of a textbox? and is it possible to print some text directly from c#? How?

推荐答案

1.您可以将所有Text复制到TextBox中:

字符串allTheText = textBox1.Text;

一个.如果您的意思是将文本复制到C#的剪贴板中,则需要阅读有关使用剪贴板的MSDN文档,并在CP上搜索此处以获取有关在C#,WinForms中使用剪贴板的信息.请参阅MSDN上的示例:[ ^ ].使用剪贴板并不难.

2.仅复制文本框中的选定文本:

字符串theSelectedText = textBox1.SelectedText;

一个.请参阅注释1.a.如果您想复制到剪贴板

3.打印文本:

一个.您需要使用System.Drawing.Printing命名空间[ ^ ]

C.一个很好的起点,这里有指向典型打印作业的操作方法的链接:"Windows窗体打印支持" [
"Windows窗体中的打印主要包括使用PrintDocument组件(Windows窗体)组件来使用户进行打印,以及使用PrintPreviewDialog控件(Windows窗体)控件,PrintDialog组件(Windows窗体)和PageSetupDialog组件(Windows窗体)组件来提供一个熟悉的图形界面,供习惯于Windows操作系统的用户使用.

通常,您将创建一个PrintDocument组件的新实例,使用PrinterSettings和PageSettings类设置描述要打印内容的属性,然后调用Print方法来实际打印文档.

从基于Windows的应用程序进行打印的过程中,PrintDocument组件将显示一个异常中止打印对话框,以提醒用户打印正在进行中并允许取消打印作业的事实." [
1. you can copy all the Text in a TextBox:

string allTheText = textBox1.Text;

a. if you mean copy the text to the Clipboard in C#: you need to read the MSDN docs on using the Clipboard, and search here on CP for information on using the Clipboard in C#, WinForms. See the examples on MSDN:[^]. Using the Clipboard is NOT difficult.

2. to copy only the selected Text in a TextBox:

string theSelectedText = textBox1.SelectedText;

a. refer to note 1.a. if you wish to copy to the Clipboard

3. Printing Text:

a. you need to use the System.Drawing.Printing NameSpace[^]

b. within that NameSpace you need to learn how to use the PrintDocument Class[^]

c. a good place to start, with links to how-to''s for typical print jobs is here: "Windows Forms Print Support"[^]"

"Printing in Windows Forms consists primarily of using the PrintDocument Component (Windows Forms) component to enable the user to print, and the PrintPreviewDialog Control (Windows Forms) control, PrintDialog Component (Windows Forms) and PageSetupDialog Component (Windows Forms) components to provide a familiar graphical interface to users accustomed to the Windows operating system.

Typically, you create a new instance of the PrintDocument component, set the properties that describe what to print using the PrinterSettings and PageSettings classes, and call the Print method to actually print the document.

During the course of printing from a Windows-based application, the PrintDocument component will show an abort print dialog box to alert users to the fact that printing is occurring and to allow the print job to be canceled."[^]


检查此链接:文本框库 [

您要将其复制到何处?属性TextBox.Text,读取属性值.

您是说复制到剪贴板"吗?您可以使用类System.Windows.Clipboard,其静态方法为System.Windows.Clipboard.SetText(string).调用它并传递上一步中从您的文本框中获得的值.

—SA
Where do you want to copy to? Just use the property TextBox.Text, read the property value.

Do you mean "copy to clipboard"? You can use the class System.Windows.Clipboard, its static method System.Windows.Clipboard.SetText(string). Call it and pass the value obtained from your text box on a previous step.

—SA


这篇关于复制文本框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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