richtextbox

C#: Paste RTF in RichTextBox but keep coloring and formatting (i.e: bold, underline, etc)

房东的猫 提交于 2019-12-02 01:46:01
问题 Is it possible to paste text into a Rich Text Box, while keeping the font being used in the Rich Text Box for the pasted content ? In other words, I'd like to copy something from Word that is formated (i.e: a text that uses a font X and is underlined and in blue), and then paste it in my RichTextBox. I would like the pasted content to have the same font as that of my RichTextBox but keep its original coloring and underlining. Is such a thing possible ? I use winforms. Thanks 回答1: This is not

Displaying Raw Data From Image File Using TextBox or RichTextBox?

会有一股神秘感。 提交于 2019-12-02 01:43:16
My program reads a DDS image file and stores it as a byte array. I want to be able to show the users the raw data in a TextBox form so at first I convert the byte array to a string using the following code: string data = System.Text.Encoding.ASCII.GetString(bytes); I then set the TextBox text: textBox.Text = data; The problem I am having is the text box is not showing all the data. Here is a screenshot of how it looks: As you can see only the first few characters are displayed. I am assuming this is because the string contains a null terminator which the TextBox interprets as the end of the

How can I prevent system clipboard image data being pasted into a WPF RichTextBox

穿精又带淫゛_ 提交于 2019-12-02 01:11:27
I have some code in place currently to intercept all Cut, Copy and Paste events into a RichTextBox in WPF. These are designed to strip all content out except plain text, and allow no pasting except plain text (by using a check the Clipboard.ContainsText() method.) This seems to be successful at preventing all such operations from inside the forms. A user can only copy, cut and paste text around, with images / audio data / random junk not being allowed. However, if I use the PrintScreen function, and paste it into one of the RichTextBoxes, the image is pasted in (not the wanted behaviour.) If

c# how can I update just one line text in richtextbox?

 ̄綄美尐妖づ 提交于 2019-12-02 01:09:44
问题 how can I update just one line text in richtextbox? String[] lines = richTextBox8.Lines; lines[2] += " "; richTextBox8.Lines = lines; I am using this code part for update second line of richtextbox but it scans all my richtextbox lines and it takes many times. so I want to update line text for 1 line. How can I do that? 回答1: Note that you must never touch the Text or the Lines directly or all previous formatting gets messed up. Here is a function that will solve the problem without messing up

Delete a specific line in a .NET RichTextBox

烈酒焚心 提交于 2019-12-02 00:36:21
问题 How can I delete a specific line of text in a RichTextBox ? 回答1: Another solution: private void DeleteLine(int a_line) { int start_index = richTextBox.GetFirstCharIndexFromLine(a_line); int count = richTextBox.Lines[a_line].Length; // Eat new line chars if (a_line < richTextBox.Lines.Length - 1) { count += richTextBox.GetFirstCharIndexFromLine(a_line + 1) - ((start_index + count - 1) + 1); } richTextBox.Text = richTextBox.Text.Remove(start_index, count); } 回答2: This also could do the trick

Capture CTRL+V or paste in a textbox in .NET

六月ゝ 毕业季﹏ 提交于 2019-12-02 00:35:47
问题 VB.NET 2010 - I have a RichTextbox in which the user can manually enter data or copy/paste from another source. After the data is complete he hits go and a few key words are highlighted. My issue is that if he copy/pastes from another source the formatting also gets copied. Well sometimes the outside source has a white font and my textbox has a white background so it appears like he pasted nothing and he does it again and again. What I'm looking for is a way to intercept the paste action into

Decide FontStyle (Bold, Italic, Underlined) for RichTextBox

隐身守侯 提交于 2019-12-02 00:18:18
How exactly do you change the Font in a RichTextBox? Looking around gives me old answers that doesn't seem to work any more. I thought it would be as simple as doing richtextbox1.Font = Font.Bold; or something similar. Turns out it's not, so I looked around. Apparently you have to change the FontStyle which is a readonly (??) property, but you have to do it making a new FontStyle Object. But even then that doesn't work o.o How do you do this? EDIT: Doesn't seem to work :\ rssTextBox.Document.Blocks.Clear(); rssTextBox.FontWeight = FontWeights.Bold; rssTextBox.AppendText("Title: "); rssTextBox

How to properly apply backgroundcolor on a text in RichTextBox

梦想的初衷 提交于 2019-12-01 23:21:03
internal string Select(RichTextBox rtb, int index, int length) { TextRange textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd); if (textRange.Text.Length >= (index + length)) { TextPointer start = textRange.Start.GetPositionAtOffset(index, LogicalDirection.Forward); TextPointer end = textRange.Start.GetPositionAtOffset(index + length, LogicalDirection.Backward); rtb.Selection.Select(start, end); rtb.Selection.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.LightBlue)); } return rtb.Selection.Text; } whenever ApplyPropertyValue is called

Delete a specific line in a .NET RichTextBox

风流意气都作罢 提交于 2019-12-01 21:51:06
How can I delete a specific line of text in a RichTextBox ? Another solution: private void DeleteLine(int a_line) { int start_index = richTextBox.GetFirstCharIndexFromLine(a_line); int count = richTextBox.Lines[a_line].Length; // Eat new line chars if (a_line < richTextBox.Lines.Length - 1) { count += richTextBox.GetFirstCharIndexFromLine(a_line + 1) - ((start_index + count - 1) + 1); } richTextBox.Text = richTextBox.Text.Remove(start_index, count); } This also could do the trick (if you can handle things such as ++ in forms code). Keeps the text format. Just remember "ReadOnly" attribute work

c# how can I update just one line text in richtextbox?

蓝咒 提交于 2019-12-01 21:50:50
how can I update just one line text in richtextbox? String[] lines = richTextBox8.Lines; lines[2] += " "; richTextBox8.Lines = lines; I am using this code part for update second line of richtextbox but it scans all my richtextbox lines and it takes many times. so I want to update line text for 1 line. How can I do that? Note that you must never touch the Text or the Lines directly or all previous formatting gets messed up. Here is a function that will solve the problem without messing up the formatting: void changeLine(RichTextBox RTB, int line, string text) { int s1 = RTB