richtextbox

How to properly apply backgroundcolor on a text in RichTextBox

让人想犯罪 __ 提交于 2019-12-04 04:22:27
问题 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

Append text to the beginning in the Rich Text Box

耗尽温柔 提交于 2019-12-04 02:57:50
问题 private void button1_Click(object sender, EventArgs e) { richTextBox1.AppendText("\r\n"); richTextBox1.Focus(); string s = "Enter "; richTextBox1.AppendText(s + "\r\n"); richTextBox1.SelectionStart = richTextBox1.Text.Length - (s.Length +1); richTextBox1.SelectionLength = s.Length +1; richTextBox1.SelectionFont = new Font("Arial", 12, FontStyle.Bold); richTextBox1.DeselectAll(); richTextBox1.SelectionStart = richTextBox1.Text.Length; richTextBox1.SelectionLength = richTextBox1.Text.Length;

Winforms RichTextBox: How can I scroll the caret to the middle of the RichTextBox?

偶尔善良 提交于 2019-12-04 01:42:56
问题 I want to scroll a RichTextBox so that the caret is approximately in the middle of the RichTextBox. Something like RichTextBox.ScrollToCaret(), except I don't want to put the caret at the very top. I saw Winforms: Screen Location of Caret Position, and of course also saw the Win32 function SetCaretPos(). But I'm not sure how to translate the x,y required by SetCaretPos into lines in the richtextbox. 回答1: If the rich text box is in _rtb, then you can get the number of visible lines: public int

Change font of text in richtextbox

一曲冷凌霜 提交于 2019-12-04 01:18:53
问题 My text is in a richtextbox: <Parag1 Level="One"> First text of parag1. Second text of parag1. </Parag1> <Parag2 Level="Two"> First text of parag2. Second text of parag2. </Parag2> <Parag3 Level="Footer"> First text of parag3. Second text of parag3. </Parag3> <Parag4 Level="Three"> First text of parag4. Second text of parag4. </Parag4> I want change color font & text color of text : 1- For tags -> font name = Tahoma , size= 10,color=red Example : <Parag1 Level="One"> Or </Parag1> 2- For Text

Detect if a RichTextBox is empty

泪湿孤枕 提交于 2019-12-04 00:32:03
What is the best way to detect if a WPF RichTextBox/FlowDocument is empty? The following works if only text is present in the document. Not if it contains UIElement's new TextRange(Document.ContentStart, Document.ContentEnd).IsEmpty You could compare the pointers, which is not all too reliable: var start = rtb.Document.ContentStart; var end = rtb.Document.ContentEnd; int difference = start.GetOffsetToPosition(end); This evaluates to 2 if the RTB is loaded, and 4 if content has been entered and removed again. If the RTB is completely cleared out e.g. via select all -> delete the value will be 0

Rich Text Box - Bold

寵の児 提交于 2019-12-04 00:14:53
I know there are loads of "how to bolden text" questions on here, but none of the answers are helping, I think it may be that the Rich Text Box is being created at runtime. I'm making a chat client, so I have a rich text box split up in lines and the messages are as follows: {Name}: {Message} \r\n I want to bolden the name, I have tried many code examples, but this is the closest I've got to it working: int length = textBox.Text.Length; textBox.Text += roomChatMessage.from + ": " + roomChatMessage.text + "\r\n"; textBox.Select(length, roomChatMessage.from.Length); textBox.SelectionFont = new

XAML to Html and vice versa

醉酒当歌 提交于 2019-12-03 20:46:10
I'm currently working on a SilverLight text editor for my site control panel, I almost done with that, but now I need to convert XAML to Html and vice versa (as you probably know Silverlight's RichTextBox returns XAML ) So I've to convert it to Html. Any idea how can I handle this ? Well, it's just XML. So convert Section and Paragraph elements to their appropriate HTML equivalents ( p and div , probably) and do so for the inlines as well ( Run expands to just the text, probably, Span gets span , LineBreak gets br , etc.). I.e. what you need to do is read the XAML as XML and create another

WPF richTextBox question

◇◆丶佛笑我妖孽 提交于 2019-12-03 16:12:20
If a line of text is wrapped to an additional line, how do I determine programmatically the point in the string where it was broken. Example: Input string = "This is a test of a wrapped line of text". Based on the width of the richTextBox it could display: This is a test of a wrapped line of text. What I need to determine is offset in the line of the word(s) that got wrapped. In the above case the word "text". When I extract the Xaml from the richTextBox, I get the original text unwrapped. Thanks, Bob Kerlinger The trick I found uses the TextPointer class and its GetCharacterRec method.

How to make <UIElement> interactable or click-able in WPF UI

烂漫一生 提交于 2019-12-03 15:33:15
This is my first day to design UI using WPF. I have looked up MSDN official document of Flow Document and found that I can place an UI control inside a RichTextBox . I did put a button in but found it's not interactable - I cannot click on it as it's grey. And I also tried other controls and they all displayed fine but just don't support interaction. Even a hyperlink doesn't work. I have searched over internet, the closest question ever asked is about how to make an inside hyperlink click-able: The similar question: C# WPF Text with links I did the same thing but it didn't work! All component

Best way to implement a Parsing/Editable Richtextbox in WPF

感情迁移 提交于 2019-12-03 15:03:37
问题 I'm trying to implement (as a prototype initially), a richtextbox control which can be parsed in real time to apply certain formatting options to it. This is being done in WPF so I thought the best way to go about it would be to extend the existing rich text box control. I've run into the issue where it isn't documented well and the examples are quite slow (the ones I found have parse the whole document on every keystroke). The way I've currently decided to go about it is to create a custom