richtextbox

How to get the current line in a RichTextBox control?

a 夏天 提交于 2019-12-05 19:31:28
Say I clicked somewhere inside a RichTextBox control. How can I get the current line the caret is currently on? Btw this is to retrieve the whole text string of that line. That's what RichTextBox.GetLineFromCharIndex() does. Pass the SelectionStart property value. This worked for me: this.WordWrap = false; int cursorPosition = this.SelectionStart; int lineIndex = this.GetLineFromCharIndex(cursorPosition); string lineText = this.Lines[lineIndex]; this.WordWrap = true; One way is to send it the EM_LINEFROMCHAR Message . I'm sure there are other ways. user718424 If you want to get current Line

Change line spacing in winform RichTextBox

吃可爱长大的小学妹 提交于 2019-12-05 19:26:06
I'm using in my winform project a RichTextBox control to display a kind of old console screen. This works perfectly but there is a space between the lines. Is it possible to change this space to be 0 or anything near that. If i paint a line from vetical line from line 1 to line 5 i don't want any spacing between the line. Hope you can help me. There's actually a lot that the Windows Forms RichTextBox doesn't expose. If you have the HWND (Handle property) to the control, you can use the SendMessage API to send the EM_SETPARAFORMAT message to play with the formatting. In particular the

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

南楼画角 提交于 2019-12-05 19:23:32
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> </InlineUIContainer> LLL </Paragraph> <Paragraph> LLL <InlineUIContainer> <Border Background=

How to move scroll bar up by one line? (In C# RichTextBox)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 17:36:28
For my C# RichTextBox, I want to programmatically do the same thing as clicking the up arrow at the top of a vertical scroll bar, which moves the RichTextBox display up by one line. What is the code for this? Thanks! Here's what I do: using System.Runtime.InteropServices; [DllImport("user32.dll")] static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam); then call: SendMessage(myRichTextBox.Handle, (uint)0x00B6, (UIntPtr)0, (IntPtr)(-1)); Seems to work OK - you might need to tweak things a bit, though. Hope that helps. For future reference the EM_LINESCROLL message

Counting lines displayed by richtextbox in C#

你说的曾经没有我的故事 提交于 2019-12-05 15:41:59
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. You may go for RichTextBox.GetLineFromCharIndex Method Retrieves the line number from the specified character position within the text of the RichTextBox control. If

How to insert XAML into RichTextBox?

孤街浪徒 提交于 2019-12-05 15:34:23
A XAML text stored in database, how can I show its text in a RichTextBox after reading the XAML by XmlReader? StringReader stringReader = new StringReader(xamlString); XmlReader xmlReader = XmlReader.Create(stringReader); rt.Document = ??? ------UPDATE------------------- here is the xamlString contents: <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="RightToLeft" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture"

Detect if a RichTextBox is empty

ⅰ亾dé卋堺 提交于 2019-12-05 14:07:20
问题 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 回答1: 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

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

ぃ、小莉子 提交于 2019-12-05 14:03:37
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 = new FontFamily("Consolas"); double fontSize = 16; char standardizationCharacter = 'X'; String

How to remove annoying BEEP with RichTextBox

[亡魂溺海] 提交于 2019-12-05 13:57:55
I placed a RichTextBox control on a new form and launched the project. So the RichTextBox.Text = ""; Each time I press Up or Down keys I heard the annoying BEEP sound! How to get rid of this issue? Using "e.SuppressKeyPress = true" in the KeyDown method locks the Cursor position. Well, you can try suppressing the key only if the caret is on the first line and the key is up, or on the last line and the key is down or in position 0 and the key is left, etc. That said, this is how most textboxes behave, and the sound is set in your operating system preferences. You'd get the same beep in, say,

Rich Text Box - Bold

社会主义新天地 提交于 2019-12-05 12:58:36
问题 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 + ": " +