I'm trying to include the font "KaiTi" while setting text on the clipboard, so that wherever I paste the data, the "KaiTi" Font will be the font that the text is in, inevitably keeping all of the data that I am pasting to the clipboard formatted the way that I want it too.
This is what I tried, I know it's off, but I don't know what to do..
TextBox texter = new TextBox();
texter.Text = strToClips;
texter.Font = new Font("KaiTi", 10);
Clipboard.SetText(texter.Text);
Use a RichTextBox. It puts rich text on the clipboard that includes formatting. Use its Copy() method. Pasting back now also works automatically without any code.
The richtextbox displayed the formatting OK, but I couldn't get Copy() to bring the font across. In the end I selected the text then sent a Ctrl-C character to copy it, as follows:-
myrichtextbox.SelectAll();
myrichtextbox.Focus();
SendKeys.Send("^C");
Related
I am trying to use CKEditor into my ASP.NET Application. I got a good resource as follows
http://www.codeproject.com/Tips/532164/How-to-Integrate-CKEditor-with-ASP-NET
http://www.codeproject.com/Tips/455129/Rich-Text-Editor-with-ASP-NET
I want to set the CKEditor Text without losing its formatting (bold, Italics etc..) into a multiline Textbox. So, I am trying the following code.
string str = this.CKEditor1.Text;
TextBox1.Text = str;
Thus its giving me a html encoded Output as follows
<p>dfgdfgfdgdfgdfgdf<strong>gdf</strong></p>
But I don't want to have those tags around but formatting should be preserved. I tried using HTMLEncode and HTMLDecode, Also used this.CKEditor1.HtmlEncodeOutput = false; but of no avail.
Is there any other way I can save the text as it is without losing formatting into my Textbox?
I know textboxes are not meant for storing formatted html outputs but I have to store this(Comments) along with a formatting in a text box(for History) in my Application. Previously they were using Plain text boxes for both comments and History. Now richtext editing is needed and hence we are tying to go this way. Any other good approaches and suggestions are most welcome.
No, a Textbox cant display formatted values. That is why you have the CKEditor.
You can still store the html formated values in the database and display them (formatted) in for example a Label
I load some texts from a database with different lengths into a textbox. (From 1 character to 1000 words...)
I use TextWrapping="Wrap", so if the text is to big for the width of the textbox, it will create a new line....
By saving the text, the added paragraph from TextWrapping="Wrap" will also be saved. But I don't want this. The original text shouldn't be changed in any way...
How can I display the text on a new line in the textbox without adding a "real" paragraph?
Is there a way I can determine if the paragraph was added from TextWrapping="Wrap" or if it belong to the original text?
Thanks
As #StevenRands mentioned, the source text won't be changed in any way by using TextWrapping.
It only affects the display of the text inside the TextBox.
Normally if you used text Wrapping,it wont affect the original source text.But anyways Before saving back to database you can remove the new line constants from your text box text which will give you the original text loaded from db.
I have formatted text in the rtf file and I load it to my richTextBox. It works fine, but then I want to remove some text parts programmatically. If I do like that:
richTextBox.LoadFile("TextFile.rtf");
richTextBox.Text = richTextBox1.Text.Substring(fromPosition, length);
text formatting disappears. I've tried to work with richTextBox.Lines, but there is no delete or edit function. All I need is to delete parts of loaded text without losing its formatting. Is it possible?
Thanks in advance.
To remove text you first select it, programmatically by setting SelectionStart and -Length. Then you use the Cut Method:
richTextBox1.SelectionStart = 20;
richTextBox1.SelectionLength = 120;
richTextBox1.Cut();
If you want to avoid putting the removed text to the clipboard you can set it to "" instead of 'cutting' it:
richTextBox1.SelectedText = ""
I want to fill richtext box with the values of a text file. The text file will come from the database.
I have done this code so far.
Byte[] txtdata = (Byte[])(objDataSet.Tables[0].Rows[0][7]);
MemoryStream txtmem = new MemoryStream(txtdata);
richTextBox_Show_Spec.LoadFile(txtmem,RichTextBoxStreamType.RichText);
But nothing shows in that richtextbox.
Any help is appreciated. Thanks
I would just use the Encoding namespace to get a character string from your bytes. Like richTextBox.Text = Encoding.UTF8.GetString(txtmem.ToArray());
or similar.
That way you can still store formatting information should you ever choose to support things like text size or color.
I have some text coming from database in a Multiline textbox, how can I copy that to the clipboard so that the user can paste it into another window or file (e.g. from my application to another textbox)? OR to notepad/word file if possible.
Clipboard.Clear(); //Clear if any old value is there in Clipboard
Clipboard.SetText("abc"); //Copy text to Clipboard
string strClip = Clipboard.GetText(); //Get text from Clipboard
There is no difference in copying text from a single or multiline TextBox to and from the clipboard using Clipboard.SetText() (and of course Clipboard.GetText()). A TextBox will still contain a single String, whether it contains line breaks or not. That's only eye candy.
From a limitations perspective, your ClipBoard.SetText() method will always only accept one single string as well, its size only limited by and to the amount of free memory at that given time.
No special code is needed to paste this text manually into applications like Notepad or Word.
Clipboard.SetText(yourTextBox.Text); is all you need.
For saving lines in text you should replace "\n" to NewLine character, as in example:
string textforClipboard = TextBox1.Text.Replace("\n", Environment.NewLine);
Clipboard.Clear();
Clipboard.SetText(textforClipboard);
System.Windows.Forms.Clipboard.SetText(..)
http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.settext.aspx