richtextbox

Inconsistent Results with RichTextBox ScrollToCaret

拜拜、爱过 提交于 2019-11-29 13:57:30
I am working with a RichTextBox in C#. It exists on a TabPage. When the TabPage is selected, I aim to populate the RichTextBox, and scroll to the end. I have tried the slight variations on solutions for this common question, the main one being along the lines of: MyRichTextBox.Select(MyRichTextBox.Text.Length, 0); MyRichTextBox.ScrollToCaret(); or: MyRichTextBox.SelectionStart = MyRichTextBox.Text.Length; MyRichTextBox.ScrollToCaret(); This is producing inconsistent results, albeit in a predictable manner. It will alternate between scrolling to the bottom, and scrolling one line short of the

WPF FlowDocument - Absolute Character Position

て烟熏妆下的殇ゞ 提交于 2019-11-29 13:29:13
问题 I have a WPF RichTextBox that I am typing some text into and then parsing the whole of the text to do processing on. During this parse, I have the absolute character positions of the start and end of each word. I would like to use these character positions to apply formatting to certain words. However, I have discovered that the FlowDocument uses TextPointer instances to mark positions in the document. I have found that I can create a TextRange by constructing it with start and end pointers.

Dynamically adding hyperlinks to a RichTextBox

旧巷老猫 提交于 2019-11-29 12:43:09
问题 I'm trying to dynamically add some hyperlinks to a RichTextBox using WPF and C# but am not having much success. My code is summarised below: FlowDocument doc = new FlowDocument(); richTextBox1.Document = doc; richTextBox1.IsReadOnly = true; Paragraph para = new Paragraph(); doc.Blocks.Add(para); Hyperlink link = new Hyperlink(); link.IsEnabled = true; link.Inlines.Add("Hyperlink"); link.NavigateUri = new Uri("http://www.google.co.uk"); link.Click += new RoutedEventHandler(this.link_Click);

How to make some text bold in a rich text box in C#

时光总嘲笑我的痴心妄想 提交于 2019-11-29 12:36:33
问题 I want to create a text editor where I can make text bold, change its color, etc. I found this code to approximately work: public static void BoldSelectedText(RichTextBox control) { control.SelectionFont = new Font(control.Font.FontFamily, control.Font.Size, FontStyle.Bold); } But when I type in more letters in the RichTextBox the text is still bold. How can I make it so that only the selected text is bold and the next characters aren't unless I select the text and hit the "Make Bold" button?

Links inside rich textbox?

两盒软妹~` 提交于 2019-11-29 11:04:42
问题 I know that richtextboxes can detect links (like http://www.yahoo.com) but is there a way for me to add links to it that looks like text but its a link? Like where you can choose the label of the link? For example instead of it appearing as http://www.yahoo.com it appears as Click here to go to yahoo edit: forgot, im using windows forms edit: is there something thats better to use (as in easier to format)? 回答1: Of course it is possible by invoking some WIN32 functionality into your control,

Open file in rich text box with C#

非 Y 不嫁゛ 提交于 2019-11-29 10:51:06
This question have been answered. I recommend sumit_programmers solution below. For now, I've removed my code, thinking it's more confusing than helpful. When I've developed it a bit further, perhaps I'll post my code here, with some comments. You may also be interested in the answer to the question Save text from rich text box with C# . There is an answer that reminds of the accepted answer to this question. The code should work, but it's written by me, so there may be some errors or missing information. Update: I have improved the code a bit (at least I think so). "Encoding.Default" seems to

Measure String inside RichTextBox Control

蹲街弑〆低调 提交于 2019-11-29 09:48:53
Can somebody please explain how I would go about measuring the string inside a richtextbox control so that the I can automatically resize the richtextbox control according to its content? Thank you Edit: I've thought about it, and since the below answer won't work if there are different fonts in the RichTextBox Control, what if, I could get the upper-left coords of the richtextbox control and then get the bottom-right coords of the very last line of text inside the rtb. That would essentially give me the Width and Height of the string inside the RichTextBox Control. Is this possible? Or is

RichTextBox color selected lines

旧时模样 提交于 2019-11-29 09:45:43
问题 I am new to windows Forms. I am using VS 2008, C# to write a RichTextBox. I want to be able to color each line with a different color as I write to the RichTextBox. Can someone point me to samples. Thanks foreach (string file in myfiles) { // As I process my files // richTextBox1.Text += "My processing results"; if(file == "somefileName") { // Color above entered line or enter new colored line } } 回答1: Set SelectionColor before you append, something like: int line = 0; foreach (string file in

C# FlowDocument to HTML conversion

岁酱吖の 提交于 2019-11-29 09:38:02
问题 Basically, I have a RichTextBox and I want to convert the formatted contents of it to HTML so it can be sent as an email. The method I am currently using does not give any formatting at all: string message = new TextRange(messageTextBox.Document.ContentStart, messageTextBox.Document.ContentEnd).Text; So I searched around and found this, however, it is over 5 years old and in the comments an MSFT user has commented saying that it is no longer supported - "This sample has been removed from our

WPF RichTextBox to create editor with line numbers [closed]

假如想象 提交于 2019-11-29 09:17:27
I'm creating a text editor for a domain specific language. I'm using the WPF RichTextBox as the basic control. I don't know how to gracefully include line numbering. Does anyone know of any examples? AvalonEdit is a good one, and it's open source. I think it has nearly all of the features of the Aqistar control such as syntax highlighting and folding. Ease to configure and use. Further details can be found here . I would create a composite control, with a stack panel control and text blocks on the left which you would use to handle the line numbering. If you are concerned with the number of