richtextbox

c# richtextbox outofmemory

强颜欢笑 提交于 2020-01-04 14:28:21
问题 I have written an app that reads incoming chat(somewhat like an instant messenger), formats it and inserts it into a richtextbox. If you leave the program running long enough you will get an out of memory error. After looking at my code i think this is because i am never trimming the richtextbox. The problem that i'm running into is i don't want to call clear() because i don't want the visible text to disappear. I was thinking maybe i should keep a List with a max size of somthing like 200

How to change cursor when mouse pointer is over a bold word in RichTextBox?

你说的曾经没有我的故事 提交于 2020-01-04 04:30:09
问题 I want to change cursor to the HAND when mouse pointer is over a bold word in RichTextBox. How to do this? 回答1: Add this function to richtextbox.OnMouseMove event. private void richTextBox2_MouseMove(object sender, MouseEventArgs e) { int c = richTextBox2.GetCharIndexFromPosition(new Point(e.X, e.Y)); richTextBox2.Select(c, 1); if (richTextBox2.SelectionFont.Bold) { richTextBox2.Cursor = Cursors.Hand; } else { richTextBox2.Cursor = Cursors.Default; } } You just need 1 char to know if it is

Open a .txt file into a richTextBox in C#

左心房为你撑大大i 提交于 2020-01-04 03:01:06
问题 I want to be able to open a .txt file up into a richtextbox in c# and also into a global variable i have made called 'notes' but don't know how to do this. This is the code i have at the moment: OpenFileDialog opentext = new OpenFileDialog(); if (opentext.ShowDialog() == DialogResult.OK) { richTextBox1.Text = opentext.FileName; Globals.notes = opentext.FileName; } Only problem is it doesn't appear in neither the richtextbox nor in the global varibale, and the global allows it to be viewed in

How can I scroll to a specified line number of a RichTextBox control using C#?

假如想象 提交于 2020-01-03 14:13:51
问题 How can I scroll to a specified line number of a RichTextBox control using C#? It's the WinForms version. 回答1: You can try something like this. void ScrollToLine(int lineNumber) { if (lineNumber > richTextBox1.Lines.Count()) return; richTextBox1.SelectionStart = richTextBox1.Find(richTextBox1.Lines[lineNumber]); richTextBox1.ScrollToCaret(); } This will not work perfectly if you have lots of repetition within your RichTextBox. I do hope that it might be of some use to you. 回答2: With this code

Richtextbox lines count

梦想的初衷 提交于 2020-01-02 17:13:12
问题 I'm developing a text editor in C#, and I'm trying to make a line count. private void updateNumberLabel() { Point pos = new Point(0, 0); int firstIndex = Document.GetCharIndexFromPosition(pos); int firstLine = Document.GetLineFromCharIndex(firstIndex); pos.X = ClientRectangle.Width; pos.Y = ClientRectangle.Height; int lastIndex = Document.GetCharIndexFromPosition(pos); int lastLine = Document.GetLineFromCharIndex(lastIndex); int actualLine = Document.GetLineFromCharIndex(actualPos); pos =

Spell checking doesn't work with WPF RichTextBox

北城以北 提交于 2020-01-02 07:32:09
问题 I'm trying to enable spell checking in a WPF RichTextBox. MSDN writes that System.Windows.Controls.SpellCheck can be used to enable spell checking for TextBox and RichTextBox controls. Unfortunately, the following code doesn't work for me: <RichTextBox SpellCheck.IsEnabled="True" xml:lang="en-US"></RichTextBox> Which is strange, because if I use a plain TextBox, it works perfectly fine (I can see the red lines if I miss-spell something). Unfortunately, every answer I've found on SO so far

C# Preventing RichTextBox from scrolling/jumping to top

不问归期 提交于 2020-01-02 07:04:56
问题 It appears that when using a System.Windows.Forms.RichTextBox you can use textbox.AppendText() or textbox.Text = "" for adding text to the textbox. AppendText will scroll to the bottom and adding the text directly will not scroll, but will jump to the top when the user has the textbox focused. Here is my function: // Function to add a line to the textbox that gets called each time I want to add something // console = textbox public void addLine(String line) { // Invoking since this function

Silverlight. How to align text in InlineUIContainer content with outer text in RichTextBox

扶醉桌前 提交于 2020-01-02 06:57:10
问题 The task: Make the text content of the InlineUIContainer to be inline with the outer text. The standard behaviour of the InlineUIContainer content is when the bottom edge is inline with the outer text. It is possible to shift the position of InlineUIContainer with RenderTransform, but the value of Y has to be chosen for each font type and size - not a perfect way. <RichTextBox> <Paragraph> LLL <InlineUIContainer> <Border Background="LightGoldenrodYellow"> <TextBlock Text="LLL"/> </Border> <

Counting lines displayed by richtextbox in C#

北城余情 提交于 2020-01-02 06:21:29
问题 In my project I want to count lines displayed by richtextbox in C# with word wrap property set true. For example, in richtextbox, I write a text, and when text reaches the width of the richtextbox, then it automatically goes to second line. So what happens is the text contains actually one line but it is displayed in two lines. So I want to know how can I count this as two lines instead of one? Help will be really appreciated. 回答1: You may go for RichTextBox.GetLineFromCharIndex Method

Setting WPF RichTextBox width and height according to the size of a monospace font

北战南征 提交于 2020-01-02 05:24:09
问题 I am trying to fit a WPF RichTextBox to exactly accommodate a grid of characters in a particular monospace font. I am currently using FormattedText to determine the width and height of my RichTextBox, but the measurements it is providing me with are too small--specifically two characters in width too small. Is there a better way to perform this task? This does not seem to be an appropriate way to determine the size of my control. RichTextBox rtb; rtb = new RichTextBox(); FontFamily fontFamily