richtextbox

why foreach is faster than for loop while reading richtextbox lines

两盒软妹~` 提交于 2019-11-28 08:14:28
问题 There are two ways to read data from RichTextBox line by line 1 ) use a for loop to loop through lines of a richtextBox String s=String.Empty; for(int i=0;i<richtextbox.lines.length;i++) { s=richTextBox.Lines[i] } 2 ) use a foreach loop to enumerate richTextBox.Lines collection String s=String.Empty; foreach(string str in txtText.Lines) { s=str; } There is a huge difference in performance when we use foreach loop to enumerate array collection for richtextbox. I tried with 15000 lines.for loop

Inconsistent Results with RichTextBox ScrollToCaret

倾然丶 夕夏残阳落幕 提交于 2019-11-28 07:25:44
问题 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

Current line and column numbers in a RichTextBox in a Winforms application

血红的双手。 提交于 2019-11-28 04:06:25
问题 How do I get the current line and column numbers in a RichTextBox in a Winforms application? NOTE Folks, I just want a simple solution, if it's available by someone and he's willing to share it with us, and not links to do research! Just give me some code please! Otherwise, I'll have to buy a control... 回答1: For row and column, check out the Richer RichTextBox project. It is an extended version of the RichTextBox which supports the row and column numbers. The code from the article: this.rtb

WinForms RichTextBox : how to reformat asynchronously, without firing TextChanged event

你离开我真会死。 提交于 2019-11-28 04:04:26
问题 This is a followup to WinForms RichTextBox: how to perform a formatting on TextChanged? I have a Winforms app with a RichTextBox, the app auto-highlights the content of said box. Because the formatting can take a long time for a large document, 10 seconds or more, I've set up a BackgroundWorker to do the re-formatting of a RichTextBox. It walks through the text and performs a series of these: rtb.Select(start, length); rtb.SelectionColor = color; While it is doing this, the UI remains

Measure String inside RichTextBox Control

試著忘記壹切 提交于 2019-11-28 03:11:29
问题 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

WPF RichTextBox to create editor with line numbers [closed]

回眸只為那壹抹淺笑 提交于 2019-11-28 02:42:06
问题 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? 回答1: 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. 回答2: I would create a composite control, with a stack panel control and text

Modifying default tab size in RichTextBox

╄→гoц情女王★ 提交于 2019-11-28 02:38:06
问题 Is there any way to change the default tab size in a .NET RichTextBox? It currently seems to be set to the equivalent of 8 spaces which is kinda large for my taste. Edit: To clarify, I want to set the global default of "\t" displays as 4 spaces for the control. From what I can understand, the SelectionTabs property requires you to select all the text first and then the the tab widths via the array. I will do this if I have to, but I would rather just change the global default once, if

Bind the text of RichTextBox from Xaml

不羁的心 提交于 2019-11-28 02:34:58
问题 How to Bind the text of RichTextArea from xaml 回答1: There is no built in way to do that. You can create Text attached property and bind to it like discussed here 回答2: They've got the easier answer here: Silverlight 4 RichTextBox Bind Data using DataContext and it works like a charm. <RichTextBox> <Paragraph> <Run Text="{Binding Path=LineFormatted}" /> </Paragraph> </RichTextBox> 回答3: Here is the solution I came up with. I created a custom RichTextViewer class and inherited from RichTextBox.

From RichTextBox to text files, line after line

a 夏天 提交于 2019-11-28 02:21:18
问题 I have trouble with saving file from Richtextbox to text file. My richtextbox looks like this; ABC ... SDE ... KLO ... After i saved it looks like this: ABC ... SDE ... KLO ... But i want the same like richtextbox line after lines. What did i do wrong? if (saveFileDialog2.ShowDialog() == DialogResult.OK) { StreamWriter sw = File.CreateText(saveFileDialog2.FileName); sw.WriteLine(richTextBox1.Text); sw.Flush(); sw.Close(); //File.WriteAllText(saveFileDialog2.FileName, str); } 回答1: You are

Change style of selected Text in RichTextBox

主宰稳场 提交于 2019-11-28 01:47:47
问题 How can I change styles (such as Font, FontSize, Brush) of selected Text in RichTextBox ? Update : Let's say I've a RichTextBox and a Toolbar. User comes and select text inside the RichTextBox box and change the font size from toolbar. I want to change style of selected text. 回答1: WPF if (this.TextEditor.Selection.IsEmpty) this.TextEditor.CurrentFontFamily = SelectedFont; else this.TextEditor.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, SelectedFont); or another WPF Example