richtextbox

How to get RTF from RichTextBox

风格不统一 提交于 2019-11-27 02:26:36
问题 How do I get the text in RTF of a RichTextBox ? I'm trying to get like this, but the property does not exist. RichTextBox rtb = new RichTextBox(); string s = rtb.Rtf; 回答1: To get the actual XAML created by the user inside of the RichTextBox: TextRange tr = new TextRange(myRichTextBox.Document.ContentStart, myRichTextBox.Document.ContentEnd); MemoryStream ms = new MemoryStream(); tr.Save(ms, DataFormats.Xaml); string xamlText = ASCIIEncoding.Default.GetString(ms.ToArray()); EDIT: I don't have

How can I access one window's control (richtextbox) from another window in wpf?

ε祈祈猫儿з 提交于 2019-11-27 02:25:44
问题 I'm sure this is something very simple but I can't figure it out. I've searched here and on msdn and have been unable to find the answer. I need to be able to set the richtextboxes selection via richtextbox.Selection.Select(TextPointer1, Textpointer2). 回答1: Application.Current contains a collection of all windows in you application, you can get the other window with a query such as var window2 = Application.Current.Windows .Cast<Window>() .FirstOrDefault(window => window is Window2) as

Detecting if paste event occurred inside a rich text box

房东的猫 提交于 2019-11-27 01:52:53
Is there a way by which we can find out if a clip board paste event occurred in a rich text box? This event would be used in order to do certain stuff, with the pasted block of text. thanks Here is my code protected override void WndProc(ref System.Windows.Forms.Message m) { if (m.Msg == WM_PASTE) { OnPasteOccurred(); MessageBox.Show("Pas"); } if (m.Msg == 0x000F) { if (PaintControl) { base.WndProc(ref m); } else { m.Result = IntPtr.Zero; } } else { base.WndProc(ref m); } } Edit I wish to do some syntax highlighting or indentation based on paste events, something which this particular code

Change color of text within a WinForms RichTextBox [duplicate]

和自甴很熟 提交于 2019-11-27 01:40:52
This question already has an answer here: Color different parts of a RichTextBox string 8 answers I have a RichTextBox that I write a string to every time I click a Form button. Each string begins with the string "Long" or "Short" and ends with a newline. Each time I add a string, it appends to the bottom of the RichTextBox. I'd like to color each line red if it beings with "Long" and blue if it begins with "Short". How can I do this? Sure, so what you can do is use the SelectionStart, SelectionLength and SelectionColor properties to accomplish this. It works quite well. Check out this page

How to access properties of a usercontrol in C#

落花浮王杯 提交于 2019-11-26 23:19:38
问题 I've made a C# usercontrol with one textbox and one richtextbox. How can I access the properties of the richtextbox from outside the usercontrol. For example.. if i put it in a form, how can i use the Text propertie of the richtextbox??? thanks 回答1: Cleanest way is to expose the desired properties as properties of your usercontrol, e.g: class MyUserControl { // expose the Text of the richtext control (read-only) public string TextOfRichTextBox { get { return richTextBox.Text; } } // expose

Selectively coloring text in RichTextBox

喜你入骨 提交于 2019-11-26 23:02:30
How can I paint in red every time I meet the letter "A" in RichTextBox? Try this: static void HighlightPhrase(RichTextBox box, string phrase, Color color) { int pos = box.SelectionStart; string s = box.Text; for (int ix = 0; ; ) { int jx = s.IndexOf(phrase, ix, StringComparison.CurrentCultureIgnoreCase); if (jx < 0) break; box.SelectionStart = jx; box.SelectionLength = phrase.Length; box.SelectionColor = color; ix = jx + 1; } box.SelectionStart = pos; box.SelectionLength = 0; } ... private void button1_Click(object sender, EventArgs e) { richTextBox1.Text = "Aardvarks are strange animals";

How to append \line into RTF using RichTextBox control

空扰寡人 提交于 2019-11-26 22:24:02
问题 When using the Microsoft RichTextBox control it is possible to add new lines like this... richtextbox.AppendText(System.Environment.NewLine); // appends \r\n However, if you now view the generated rtf the \r\n characters are converted to \par not \line How do I insert a \line control code into the generated RTF? What does't work: Token Replacement Hacks like inserting a token at the end of the string and then replacing it after the fact, so something like this: string text = "my text"; text =

How can I make a hyperlink work in a RichTextBox?

≯℡__Kan透↙ 提交于 2019-11-26 22:19:02
When I add www.stackoverflow.com into my RichTextBox and run the program it is shown in blue and as a hyperlink yet when I click it nothing happens. How can I fix this? Make sure the text property includes a valid url. E.g. http://www.stackoverflow.com/ set the DetectUrls property to true Write an event handler for the LinkClicked event. Personally, I wouldn't pass "IExplore.exe" in as a parameter to the Process.Start call as Microsoft advise as this presupposes that it is installed, and is the user's preferred browser. If you just pass the url to process start (as per below) then Windows will

A textbox/richtextbox that has syntax highlighting? [C#] [closed]

不问归期 提交于 2019-11-26 21:45:16
Where can I find a control for WinForms that will highlight source code pasted into it? I would like one that has syntax highlighting support for many different languages but if it only works with C# I would be fine with that also. Scintilla.NET is probably what you're looking for Just recently have found a nice control from codeproject Fast Colored TextBox for syntax highlighting . The only issue with using Rich Text Box as highlighter is slow performance on coloring, in cases when the size of the document is big. For a medium size documents this issue can be fixed by delayed highlighting. As

How can I use NLog's RichTextBox Target in WPF application?

此生再无相见时 提交于 2019-11-26 20:46:59
问题 How can I use RichTextBox Target in WPF application? I don't want to have a separate window with log, I want all log messages to be outputted in richTextBox located in WPF dialog. I've tried to use WindowsFormsHost with RichTextBox box inside but that does not worked for me: NLog opened separate Windows Form anyway. 回答1: If you define a RichTextBoxTarget in the config file, a new form is automatically created. This is because NLog initializes before your (named) form and control has been