WPF Textbox - How to save text without the wrapping-paragraph - c#

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.

Related

CKEditor.Text is giving HTMLEncoded Output in ASP.NET

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

Losing table width autosize when saving RTF from RichTextBox

Ok, so I have a RichTextBox user control in which the user can enter any number of Rich Text elements which then converts the contents to HTML. At the moment, I am working on tables specifically. For the most part, they work pretty easily, but when I try to save the RTF to a file and then load it again, the \trautofit1 control word disappears and the table width is reduced.
To save to an RTF file, I'm using: TextRange.Save(fileStream, DataFormats.Rtf);
I'm pretty sure the issue comes with how the RTF is saved, because the file that results from this has the shrunken table as well.
Here is the table before the save:
Here is the table after the save and load:
So the question: Is there anyway in which to counter this behavior, or is there a better way to get the RTF, or should I be using a different control word to autosize the width of the table?
Ok, well I found a solution but it isn't exactly what I was looking for. What brought about the decision to go this route was that this is how Word does it. When you go to create the table, I find the size of the RichTextBox, then divide it by the number of columns, then I explicitly set the width of each column with \cellx. Not the pretty solution I was looking for, but it works.
I used another hack solution, before saving data I change columns width:
if (table != null && table.Columns.Count == 2)
{
table.Columns[0].Width = new GridLength(200);
table.Columns[1].Width = new GridLength(200);
document.Blocks.Add(table);
}

How to copy the contents of a Multiline textbox to the clipboard in C#?

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

Include Font while pasting to Clipboard

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");

Remove text box of MS word document

I have few MS word documents which contains text in text boxes. I want to remove those text boxes but keep the data as it. How can i do it ?
I think you can get hold of the text from inside the textboxes using something like ActiveDocument.Shapes(1).TextFrame.TextRange.Text and then you could delete it by doing something like ActiveDocument.Shapes(1).Delete, and after that you'd have to put the text you retrieved from the text box in the relevant part of the document.

Categories

Resources