Click here to Skip to main content
15,921,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
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?
Posted
Updated 13-Jan-12 1:10am
v2

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."[^]
 
Share this answer
 
Comments
i.fakhari 14-Jan-12 11:22am    
thank you

it was a perfect answer :D
Check this link:TextBox Library[^]
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900