Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a fixed line spacing in a textbox?

I am creating a software for note-taking. I created an image of a notebook with the lines, and etc. Now, I want to create a textbox (or rich text box, or whatever element that works) that will add the text exactly on top of each line.

figure

However, as the user types more than a few lines, the texts gets shifted a little bit on each line, ending up very weird.

I looked through many forums and questions in trying to have this fixed. Nothing helped. I'm developing it in Visual Studio, WPF project, C#. I want to add this control to the C# code, no XAML.

like image 717
Rafael Salgado Avatar asked Oct 17 '16 16:10

Rafael Salgado


1 Answers

Try Setting the LineStackingStrategy property.

p.LineStackingStrategy = LineStackingStrategy.BlockLineHeight;

If you need some spacing before the line also, like on starting of a paragraph then you can try setting the property as:

p.LineStackingStrategy = LineStackingStrategy.MaxHeight;

Check this Post: WPF- "LineSpacing" in a TextBlock

like image 113
The Rookie Coder Avatar answered Sep 25 '22 19:09

The Rookie Coder