richtextbox

WPF RichTextBox: How to change selected text font?

泄露秘密 提交于 2019-11-28 11:44:13
how can I change the font for a currently selected text area inside a WPF RichTextBox? I've implemented a toolbar that can change the font size, family, color, etc. What i found is the details can be tricky with the wpf richtextbox. Setting the selection font makes some sense, but, there are also the default font properties of the text box, and the current caret properties to contend with. Here is what i've written to get it to work for most cases with the font size. The process should be the same for fontfamily and fontcolor. Hope it helps. public static void SetFontSize(RichTextBox target,

C# / WPF: Richtextbox: Find all Images

回眸只為那壹抹淺笑 提交于 2019-11-28 11:35:45
i want a chat with inline images. The richtextbox good, because i can place images in it, but i want to send the text / images separate. -first: send the text (and place a image-placeholder in the text). -second: send the image and replace it with the placeholder. For that i need to remove all images in the richtextbox (and send them separate). But how can i find the images? And btw: Is it possible to rescale the image dependent on the width of the richtextbox? Thank you :) To find all images in a RichTextBox, you need to traverse through all Paragraphs and its Inlines; and then you can do

RichTextBox font set to all lines in C#

独自空忆成欢 提交于 2019-11-28 10:25:30
问题 I changed the font of a RichTextBox, but this change does not set to all of its characters properly. Indeed there exist two font for the RichTextBox and that is not beautiful. Is there a solution for this problem!? This code does not work correctly: this.richTextBox1.Font = new System.Drawing.Font("Maiandra GD", 12); 回答1: Set the selection to the entire box and set the SelectionFont. this.richTextBox1.SelectionStart = 0; this.richTextBox1.SelectionLength = this.richTextBox1.SelectionLength;

Format text in Rich Text Box

自闭症网瘾萝莉.ら 提交于 2019-11-28 10:10:55
How Can I format text in Rich Text Box like the following 02/11/2010 - 05:15 PM - Adam: Another test notes added on 2nd November 02/11/2010 - 05:14 PM - Z_kas: Test Notes. STAGE CHANGED TO: N Enq - Send Quote 02/11/2010 - 05:12 PM - user32: Another test notes added on 2nd November Thanks Mikael as stated by others there is a possible duplication with an earlier question. However, please see a code snippet below. You don’t have to get the length of the text you append in order to change its formatting, just set the format before you append. This (i think) gives better performance if you have a

Substract Flag From FontStyle (Toggling FontStyles) [C#]

时光总嘲笑我的痴心妄想 提交于 2019-11-28 10:07:59
I have a little problem. I have one 1 RichTextBox and 2 Buttons. I have that 2 buttons for "toggle Bold FStyle" and "toggle Italic FStyle". I want to toggle FontStyles without affecting other FontStyles. I hope you understand me. Below code works when combining FontStyles but is not working when seperating/substracting FontStyles . private void button1_Click(object sender, EventArgs e) { richTextBox1.SelectionFont = new Font(richTextBox1.Font, (richTextBox1.SelectionFont.Bold == false ? richTextBox1.SelectionFont.Style | FontStyle.Bold : richTextBox1.SelectionFont.Style)); } private void

How to change the background color of a rich text box when it is disabled?

安稳与你 提交于 2019-11-28 09:52:47
Whenever I set the RichTextBox.Enabled property to false, its background color is automatically set to gray as it is set to the color in system color which is set in the control panel. How can I change its color to black even if I set it to disabled? Mikael Svenson See: How to change the font color of a disabled TextBox? [Edit - code example added] richTextBox.TabStop = false; richTextBox.ReadOnly = true; richTextBox.BackColor = Color.DimGray; richTextBox.Cursor = Cursors.Arrow; richTextBox.Enter += richTextBox_Enter; private void richTextBox_Enter(object sender, EventArgs e) { // you need to

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

♀尐吖头ヾ 提交于 2019-11-28 09:27:11
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). Ian Oakes 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 Window2; and then you can reference the control from your code, as in var richText = window2

Rich Text box scroll to the bottom when new data is written to it

霸气de小男生 提交于 2019-11-28 08:51:25
My program calls Java and then redirects stdout to a RichTextBox . My problem is that the vertical scrollbar always stays at the top of the box every time data is written. Even if you scroll to the bottom, once new data has been written it goes to the top. I would like the opposite. So when new data is written, it stays at the bottom. How can I do this? Yes, you can use the ScrollToCaret() method: // bind this method to its TextChanged event handler: // richTextBox.TextChanged += richTextBox_TextChanged; private void richTextBox_TextChanged(object sender, EventArgs e) { // set the current

WPF RichTextBox Syntax Highlighting Issue

懵懂的女人 提交于 2019-11-28 08:48:19
Hello everyone I've been working on a WPF application that has a text editor this text editor should apply some styling or colorizing over some tokens (keywords) to highlight it and make it obvious,,, the problem is i tried very very hard but i still get the same result which is when the user enters one of the keywords the whole text after that keyword is being styled ! just imagine if you types the " string " keyword in " C# " the whole text after it will be colored blue. this was the code i used: static List<string> tags = new List<string>(); static List<char> specials = new List<char>();

How to get RTF from RichTextBox

て烟熏妆下的殇ゞ 提交于 2019-11-28 08:36:21
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; 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 code in front of me to test, but an instance of the TextRange type has a Save (to stream) method that takes