richtextbox

WPF RichTextBox - Selected Block?

隐身守侯 提交于 2019-11-30 23:53:44
I am experimenting with the WPF RichTextBox and notice that I can itterate through the blocks that make up its document by looping through RichTextBox.Document.Blocks. What is the best way to get the Block that surrounds the caret? I can get the CaretPosition and the ElementStart and ElementEnd properties of each block but can't see how to compare them because the actual character offsets are not exposed unless I am missing something obvious. var curCaret = richTextBox1.CaretPosition; var curBlock = richTextBox1.Document.Blocks.Where(x => x.ContentStart.CompareTo(curCaret) == -1 && x

Converting tabs into spaces in a RichTextBox

痞子三分冷 提交于 2019-11-30 20:54:25
问题 I have a WinForms application with a RichTextBox control on the form. Right now, I have the AcceptsTabs property set to true so that when Tab is hit, it inserts a tab character. What I would like to do though is make it so that when Tab is hit, 4 spaces are inserted instead of a \t tab character (I'm using a monospaced font). How can I do this? 回答1: Add a new class to override your RichTextBox : class MyRichTextBox : RichTextBox { protected override bool ProcessCmdKey(ref Message msg, Keys

How can I use a RichTextBox as a NLog Target in a WPF application?

荒凉一梦 提交于 2019-11-30 20:27:09
I read the following posts but neither helped to just get the same efficient way of printing logs from NLog onto a RichTextBox control target as in Winforms. How can I use NLog's RichTextBox Target in WPF application? WPF: Binding RichTextBox to Logger Output I also browsed the official forum but with no success (except suggestions to read the two above posts). The idea would be to add the target as: <target xsi:type="RichTextBox" name="console" layout="${longdate:useUTC=true}|${level:uppercase=true}|${logger}::${message}" autoScroll="true" maxLines="1000000" controlName="rtbConsole" formName=

Bold in RichtextBox

我们两清 提交于 2019-11-30 18:50:01
问题 I've been working on my richtextbox but I ran into something weird... I want to make the first word on everyline bold using this code: RichTextBox bold = richTextBox1; foreach (string line in bold.Lines) { string name = line.Split(' ')[0]; int srt = bold.Find(name); bold.Select(srt, name.Length); bold.SelectionFont = new Font(bold.Font, FontStyle.Bold); } But for some reason some lines are skipped. From what I noticed it depends on what word the line starts with e.g Name: gets skipped but

WPF RichTextBox - Selected Block?

[亡魂溺海] 提交于 2019-11-30 18:32:31
问题 I am experimenting with the WPF RichTextBox and notice that I can itterate through the blocks that make up its document by looping through RichTextBox.Document.Blocks. What is the best way to get the Block that surrounds the caret? I can get the CaretPosition and the ElementStart and ElementEnd properties of each block but can't see how to compare them because the actual character offsets are not exposed unless I am missing something obvious. 回答1: var curCaret = richTextBox1.CaretPosition;

How to override copy and paste in richtextbox

元气小坏坏 提交于 2019-11-30 13:55:33
How can I override the copy/paste functions in a Richtextbox C# application. Including ctrl-c/ctrl-v and right click copy/paste. It's WPF richtextBox. Edwin de Koning To override the command functions: protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Control | Keys.C)) { //your implementation return true; } else if (keyData == (Keys.Control | Keys.V)) { //your implementation return true; } else { return base.ProcessCmdKey(ref msg, keyData); } } And right-clicking is not supported in a Winforms RichTextBox --EDIT-- Realized too late this was a WPF

WPF: How to make RichTextBox look like TextBlock?

痴心易碎 提交于 2019-11-30 11:51:40
How can I make RichTextBox with no Margin, Border, Padding etc. ? In another words to display content in the same way as TextBlock does it ? I have tried this: <RichTextBox Margin="0" Padding="0" Grid.Row="0" BorderThickness="0" > <FlowDocument > <Paragraph>LLL</Paragraph> </FlowDocument> </RichTextBox> <TextBlock>LLL</TextBlock> But the result produces is still not what I want: There is still some space before document content (and also maybe after, on the top or bottom of the document...). How can I remove it ? If you are interested why I need this: I trying to make H.B.'s answer to my

c# - perfect syntax highlighting [closed]

試著忘記壹切 提交于 2019-11-30 11:31:02
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 11 months ago . I'm looking for a RichTextBox with syntax highlighting! Sounds easy but I'm searching since months and didn't find that what I need. First I started to do it by myself... No good idea... I tried to use this: http://blogs.microsoft.co.il/blogs/tamir/archive/2006/12/14/RichTextBox-syntax-highlighting.aspx but

How do I scroll a RichTextBox to the bottom?

守給你的承諾、 提交于 2019-11-30 10:52:22
问题 I need to be able to scroll a RichTextBox to the bottom, even when I am not appending text. I know I can append text, and then use that to set the selection start. However I want to ensure it is at the bottom for visual reasons, so I am not adding any text. 回答1: You could try setting the SelectionStart property to the length of the text and then call the ScrollToCaret method. richTextBox.SelectionStart = richTextBox.Text.Length; richTextBox.ScrollToCaret(); 回答2: The RichTextBox will stay

Javascript - Change font color of certain text in textarea

徘徊边缘 提交于 2019-11-30 09:29:36
Is there any JS function that can change the color of certain text in a textarea? For example, blar blar {blar} blar, {blar}, including { }, will be in blue. Other words will be in blank. In other words, all I need is a function that can change color of all text in { }. I've done some studies and it seems that most people say it can't be done. But I'm seeing rich text editors or those wysiwyg editors having the ability to bold or underline words. There must be a way to do it. Any suggestion is welcome. No one mentioned contentEditable? Just make a contentEditable div and use javascript to