How to fill richtextbox from memory stream? - c#

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.

Related

Reading Binary File With ASCII(NUL,ESC etc) and Characters to a richtextbox(Raw Data Representation similar to Notepad++)

Can anyone help me in providing the source code for the below post.
Displaying Raw Data From Image File Using TextBox or RichTextBox?
I just want the Notepad++ Content in the above post to be displayed in a richtextbox.
Thanks in Advance.
string data = System.Text.Encoding.ASCII.GetString(bytes);
richTextBox.Text = data;

How to disable the Textbox's text encoding before saving it into the data base?

I entered the text "J&K"(Without Cotes) in my StateCode textbox and saved it into database(SqlServer). But it saved as J & amp; K. So m not able to fetch the data saved, with J&K(Primery key). How can I disable encoding of text before saving it to database?
You can use the HttpUtility.HtmlDecode Method to remove the encoding.
Use Server.HtmlEncode("YourTextWith<and>Characters") for this activity.
wrap your output text within it.
Or,
This can also be helpfull>>
System.Web.UI.HtmlControls.HtmlTextArea textBox = new System.Web.UI.HtmlControls.HtmlTextArea();
textBox.Value = "j&k";
Hope its helpful.

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

How to display data inside a textbox?

My question is that I have extracted data from a file and pushed into a string variable.
I have a FORM created in visual studio having a text box, so I want to display that extracted data in textbox created.
How can achieve this?
You can do it like this:
yourTextBox.Text = yourString;
For a TextBox, it is just
myTextBox.Text = myStringVariable;
But if the data is large, you may want to consider the RichTextBox control instead.
This is all assuming you're using Windows Forms...
string strName="someone";
TextBox1.Text=strName;
If you trim the data to remove the unwanted trailing spaces if there is any.
TextBox1.Text=strName.Trim();

Categories

Resources