richtextbox

Is there a way to group or temporarily disable the undo history for a RichTextBox?

北慕城南 提交于 2019-12-05 12:37:05
问题 I'm currently wrestling with Tables inside RichTextBoxs in WPF. In WPF, tables don't have rows and columns, they just have rows, each having a certain number of cells. When a user presses the "Add Column" button, my program adds a new cell to each row. The problem with using this method is after a user adds a column, if they press undo, it removes each cell one by one, obviously not what the user would expect. Does anyone know a way to temporarily disable the addition of actions to the undo

what is best way to sort lines in RichTextBox

一笑奈何 提交于 2019-12-05 12:29:44
I'm looking for the best way to sort lines of RichTextBox, I'm using this at moment: public void SortLines(object sender, EventArgs e) { TextPointer pStart = TextInput.Document.ContentStart; TextPointer pEnd = TextInput.Document.ContentEnd; TextRange text = new TextRange(pStart, pEnd); string[] lines = text.Text.Split('\n'); Array.Sort(lines); text.Text = String.Join(String.Empty, lines); } Is there an best way to do this? When I call it, the cursor is placed into first RichTextBox line, how do I to put it where it was before? I tried to set pStart/pEnd and CaretPositiom, but the properties

Disable the selection highlight in RichTextBox or TextBox

ⅰ亾dé卋堺 提交于 2019-12-05 11:50:57
How can I disable the selection highlight of RichTexBox or TextBox in my Windows Forms Application as shown in the image. I need to change selection highlight color from Blue to White , because I need to hide selection in TextBox or RichTextBox all the time. I tried to use RichTextBox.HideSelection = true , but it doesn't not work as I expect. You can handle WM_SETFOCUS message of RichTextBox and replace it with WM_KILLFOCUS . In the following code, I've created a ExRichTextBox class having Selectable property: Selectable : Enables or disables selection highlight. If you set Selectable to

RichTextBox (.NET Winforms) problem (or alternative)

孤人 提交于 2019-12-05 11:04:41
I have a problem with .Net's RichTextBox control. It seems that it doesn't support table cell formatting, which is funny because most of the time I create tables I want the cell contents to be right-aligned (numbers, currency). If I try to open a WordPad document in RichTextBox, it ignores (and actually removes ) the commands for cell alignment. I tried several workarounds but didn't succeed. Can anyone think of an idea to fix this? (without using fixed-width fonts and spaces) This would be the best solution since other code is working fine already, so if only thing needed is a dirty hack, it

richtextbox advanced editing

五迷三道 提交于 2019-12-05 07:18:45
I am wanting to use advanced editing features with a RichTextBox i am using. For example, bold, italic, underline, font color.... I was wondering how i would get a toolbar that would show up at the top of the RichTextBox with those features? And i was wondering if there was anything that offered this functionality built in, or am i going to have to create all of it myself? I was thinking that the richtextbox would come with that toolbar by default, but it doesnt seem too. I actually found what i wanted. Here are my results: This one offers bullets and more stuff. I chose this one, because it

Adding text in a new line in WPF RichTextBox at runtime

微笑、不失礼 提交于 2019-12-05 07:09:35
I want to add some text in a WPF RichTextBox at runtime in a new line. I can do this using: FlowDocument mcFlowDoc = new FlowDocument(); mcFlowDoc = richTextBox.Document; Paragraph pr = new Paragraph(); pr.Inlines.Add(status); mcFlowDoc.Blocks.Add(pr); StatusText.Document = mcFlowDoc; But there is too much of a gap between two lines. How can I fix this? According to the documentation, Paragraph spacing is defined by margins, which do not accumulate (no doubling up), so Julien Lebosquain's answer is correct. MSDN on FlowDocument Paragraph Spacing To avoid having to manually set the margin for

superscripts are not coming in wpf richtext box

99封情书 提交于 2019-12-05 07:08:41
I have implemented a custom rich text box in a wpf mvvm application and have given option to format the entered text like this: <Button Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleBold" ToolTip="Bold"> <TextBlock FontWeight="Bold">B</TextBlock> </Button> I am using EditingCommands.ToggleBold to make the text bold. In the same way I am giving the option for ToggleSuperscript <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleSuperscript" ToolTip="Superscript"> <TextBlock FontStyle="Italic" FontWeight="Bold">SubScript</TextBlock> </Button

Show ToolTip on RichTextBox

扶醉桌前 提交于 2019-12-04 21:42:45
I have a RichTextBox on a WPF Window. Now, I want to show a ToolTip when the user move the mouse over the RichTextBox. The Content of the RichTextBox should depend on the Text which is under the mouse pointer. For this I should get the position of the char, on which the mouse shows to. Best Regards, Thomas In the following example the tooltip will show the next character where the caret is. Xaml: <Window x:Class="Test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525">

What is the most efficient way to count all of the words in a richtextbox?

核能气质少年 提交于 2019-12-04 17:56:41
I am writing a text editor and need to provide a live word count. Right now I am using this extension method: public static int WordCount(this string s) { s = s.TrimEnd(); if (String.IsNullOrEmpty(s)) return 0; int count = 0; bool lastWasWordChar = false; foreach (char c in s) { if (Char.IsLetterOrDigit(c) || c == '_' || c == '\'' || c == '-') { lastWasWordChar = true; continue; } if (lastWasWordChar) { lastWasWordChar = false; count++; } } if (!lastWasWordChar) count--; return count + 1; } I have it set so that the word count runs on the richtextbox's text every tenth of a second (if the

WPF RichTextBox - get whole word at current caret position

社会主义新天地 提交于 2019-12-04 17:13:58
I enabled spelling on my WPF richtextbox and I want to get the misspelled word at current caret position before the context menu with spelling suggestions is displayed. Subhash Lama The new way void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Back) { TextPointer start = richTextBox1.CaretPosition; string text1 = start.GetTextInRun(LogicalDirection.Backward); TextPointer end = start.GetNextContextPosition(LogicalDirection.Backward); string text2 = end.GetTextInRun(LogicalDirection.Backward); richTextBox1.Selection.Select(start, end); richTextBox1.Selection