Change line spacing in winform RichTextBox - c#

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 PARAFORMAT2 structure does have some line spacing options that may be relevant. You will have to get your hands dirty with interop though.

Related

How do I set equal character spacing in AvalonEdit such that visual line columns are the same as document line columns

I'm wrapping AvalonEdit into a custom control and I'm trying to display a text file using equal character spacing such that it behaves similarly to notepad. I've done quite a bit of digging but I can't seem to find which property I need to flip to get equal character spacing.
Thanks
Quick fix here. I found that if I just change the font to Consolas it works out just fine. I'm going to stick to this for now.

How to strike out the texts in Paragraph?

I am developing an app for Windows 8.1
The App parses HTML codes, and displays the contents on RichTextBlock.
Anyway, I'm trying to display some texts with 'StrikeThrough' line. like shown below.
I searched through the web, but I just found that there is no native way to do that on WIndows 8.1
I tried the solution on 'StrikeThrough effect on a TextBlock', but I don't think this solution can display some texts which exceed the width of RichTextBlock (I need those texts to be displayed in new line.)
Also, I don't display texts on TextBlock directly,
In my app, texts are displayed like below
RichTextBlock - Paragraph - Run (Texts)
Is there any good solution for this problem?
(The easiest way to display 'Strikeout texts' on RichTextBlock)
Thanks in advance.
Add this to your text
TextBlock1.TextDecorations = TextDecorations.Strikethrough;

Suppressing word wrap in TextBox and RichTextBox (yes, it is turned off)

I have tried both the regular TextBox and RichTextBox in an app where I don't want any word wrap. Yes, of course I turned off word wrap in Properties. This is something that occurs at extremely long lines, like around 3000 chars or so in the RichTextBox (regular TextBox much sooner, but I can get by without it if RichTextBox works). I recognize that it is cruel and unusual punishment to subject the poor RichTextBox to such line lengths, but unavoidable. Still, it seems like abnormal behavior.
The text is just long continuous strings of repetitive ascii (genetic data), so nothing unusual there. In fact it's usually just A,C,T,G with no punctuation or spaces.
Is this known behavior?
Assuming you are using WinForms, both RichTextBox and TextBox have built-in limits for lengths of lines.
An alternative is to use a scroll viewer and manually add Labels. I do not believe there will be any limit in this scenario, although I could be wrong.
If you check Notepad (notepad.exe) in Windows, it also has a limit before it starts wrapping text, so this is standard behavior for Windows apps.
the Multiline property should be false in order for the lines not to wrap.
You could try a RichTextBox and extend the right margin to the width of the text.
richTextBox1.RightMargin = TextRenderer.MeasureText(yourString, this.richTextBox1.Font).Width;
This way you maintain the ability to have other lines.

RichTextBox losing selection/caret position when changing underlying's FlowDocument's text

I've implemented "ChangeCase" keyboard shortcut (like Shift+F3 in MS WORD) for RichTextBox, which changes the text either selected by mouse, or the last word before caret's position. The problem is, it SOMETIMES loses the selection, or moves the caret one word left.
Once it changes the textcase without this changing of caret position, then it never changes the caret position (propably some WPF's internal caching.), so it can only happen the first time i run this function to a portion of text.
The code used is the solution mentioned in here WPF Flowdocument "change case" feature .
One problematic section of code is certainly
end = this.CaretPosition;
EditingCommands.MoveLeftByWord.Execute(null, this);
start = this.CaretPosition;
this.CaretPosition = end;
However I have no idea why it only occurs sometimes and how to fix this.
I thing it has something to do with the execution speed of this Execute() method and some side effects, because at my WPF app it only happens sometimes, but when hosting this WPF control in Winforms, moving the caret one word left happens all the time (if I hold Shift+F3, the cursor moves word by word to the very beginning of the document)
Other problem can be related with changing text of a TextRange, which is resulting in losing the selection? But again, it doesnt happen all the time and I have no clue how to fix it.
Any ideas?
I ended up with 2 options, ignoring this error or implementing the
MoveLeftByWord
logic manully without touching the
CaretPosition

Winforms RichTextBox Pagesize?

When I am viewing a document in Wordpad (or Word) the text is word wrapped around the document boundaries. Altough when I using the RTF string in a RichTextBox the text is wrapped around the control border.
This means when I change the size of the window the wordwrapping changes.
Is there something I can do about this ?
(some kind of mode I have to set the RichTextBox into)
Or is there are free / commercial RichTextBox which does exactly that ?
(In former times you could download the Wordpad sourcecode what I did - but I can't get it to run - is this the correct version - or does this help me at all ?)
You can control that with the RightMargin property. You'll have to figure out what your desired Width is in pixels. The default is 0 which means follow the control.
Additional: If you only need a ReadOnly view you can use a PrintPreview Control. See this article about how to get the Page transitions working.

Categories