Line spacing for different FontSizes in WPF RichtextBox - wpf

I want my RichtextBox to enable line spacing chosen by user (multiplier of 1, 1.5 or 2). I tried to programatically change LineHeight of paragraphs, setting it to FontSize*multiplier. That works fine, but it can't be used for different fontSizes in the same paragraph, because then I have to choose one of the sizes for the calculation of LineHeight.
I would like to have it similar like in WordPad or OpenOffice, where the actual LineHeight is calculated for each line using the biggest fontSize used on the line.
Is there any possibility to change the LineHeight for lines or to tell the RichTextBox to just use the multiplier? Or any other solution?

I think you are looking for the LineStackingStrategy="MaxHeight" for the Blocks. See this page: http://msdn.microsoft.com/en-us/library/system.windows.documents.block.linestackingstrategy.aspx

Related

Multiline Textbox Vertical Spacing (Winform)

I am using the standard textbox control on a Windows form. I want to display the text VERTICALLY rather than horizontally. To accomplish this I set the multiline property to true, the TextAligh property to center and used the lines property to input each character as a separate array element. So far, so good.
I see the text displayed the way I want but would like to reduce the vertical spacing between lines without reducing the font size. Can it be done? If so, how?
It can be done, but not by the default options on a standard textbox.
You would probably need to override the Paint event and draw the text yourself, but it would get very ugly, and would essentially be reinventing the standard Paint method.

RichTextBox SelectionFont is unexpectedly *not* null

I'd like to change the font size of a chunk of RTF without erasing the bold / italic / underline formatting (an issue similar to the one in this question). The accepted answer is to modify the selection of the text box until the SelectionFont propery is null in order to find runs of consistently formatted text which can be modified individually. Sounds reasonable. However the actual behavior of the RichTextBox control seems to be inconsistent with the documentation.
In the documentation for RichTextBox.SelectionFont MSDN states:
If the current text selection has more than one font specified, this
property is null.
However, this code which uses mixed bold / regular text doesn't behave as you'd expect:
var rtb = new RichTextBox {
Rtf = #"{\rtf1 This is \b bold\b0.}"
};
rtb.SelectAll();
// Now you'd expect rtb.SelectionFont to be null,
// but it actually returns a Font object
Is there any other reliable way of formatting the text so that I can change the font size without clobbering the other formatting. (Manipulating the RTF directly is OK, I'm not absolutely set on using WinForms to achieve this).
I've given up on trying to go through Winforms to fix this. As I'm applying the change to a whole document (rather than just one portion), it turns out that it's not too hard to modify the RTF directly.
In this case I'm interested in the font size, which is represented by the \fs command. So to replace all the 8.5pt text with 10pt text, you can replace \fs17 with \fs20. (Yes, RTF font sizes come in units of half a point, apparently).
This seems to work well enough, although it does feel like one of those "let's mangle our HTML using regular expressions" type solutions, so I'm not convinced that it's very robust.
Take a look at this:
Changing font for richtextbox without losing formatting
I think it's the same issue. LarsTech's solution is working perfectly for me.

DevExpress MemoEdit layout issue

I want to show some text inside the MemoEdit in two columns. The parse of the text works correctly because when I see the parsed text inside Notepad or when I debug it inside Visual Studio it shows it in two columns, so the text is formatted exactly in the way I need it. The problem is that when it is shown inside the MemoEdit, it doesn't keep the format (I think this is because it uses a different font for the text, not a fixed size width font, because white spaces are smaller then normal characters). I changed the font to some fixed size width font and is showing it correctly, but the problem is that I need to have the same font like the application uses. Is there any property on MemoEdit that can help me achive the behavior I want without changing the font?
Thanks a lot!
You can activate the RowAutoHeight option of the GridView.OptionsView property in GUI and you can set it pragmatically as below:
gridView1.OptionsView.RowAutoHeight = true;
You can also use CalcRowHeight event handler to tweak the height of the gridview rows. check the reference links.
Reference these DevExpress fourm thread -
Auto-height of grid rows and text WordWrap
GridControl row height (cell height)
Changing row height at runtime

How to highlight portion of a Rich TextBox WPF control if there are more than 2 spaces?

I have a richtextbox control in my WPF 4.0 application. Now suppose I have a text like
"hello how [space][space] r u? [space][space] I am fine"
As can be noticed that there are two gaps between how and r as well as between ? and I.
When this will happen then the portion will be highlighted with green e.g. how ..r and from ? to I will be highlighted with green color.
i.e. if the space between two words are more than 2 then that will be highlighted with green.
Is it possible to do in WPF RichTextbox control? If so, please help me in writing so. As of now what I have done is that I have only able to find out the distance of spaces between two words.
Note:~ [Space] means the white spaces. Since the gap was not prominent(as it was not coming in the editor), that's the reason I made it like so.
Thanks
WPF4.0/ C#4.0
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/7c9a622a-4e3b-451e-bc4c-ab9d011447e0
Here is a progressive scenario featuring RichTextBox highlighting multiple ranges, it may lead you on the right path.
He ends up getting it to work, but you will have to modify it to recognize white space perhaps.

Silverlight 3 - Control over wrapping in TextBox

Ok I have the following problem in Silverlight. I have a control with 2 columns. On the left is a stack panel with line numbers and on the right is a textBox.
So when I write in textBox without wrapping turned on I can simply create the right count of numbers on the left, because I'm searching for '\r' in text.
But when I turn on wrapping I have no control over the count of lines in textBox.
Is there a way to get to that count? Or a way to know which line in textBox is going to wrap?
I hope you can understand what I'm trying to do.
There's one way to do this. You can simulate the word wrap operation in the background using a TextBlock. Here is a good link of the complete solution to this problem.
Extended TextBox control with MaxLines property
Is it not possible to create your items in code before they are passed to the view. This would enable you to bind a list of items to a listview and style them as you wish.
You need to user a value converter to count the number of char / lines and then trim that number if you wish to. Unless you use fixed width, you can't really count or calculte in advancet the size, since each application might be displayed differently (due to different sizing option).
There are two great sample chapters on Windows Phone and Silverlight for Windows Phone on the LearningWindosPhone.com site. There is great Windows Phone Trainng material , and dont forget the Windows Phone Develoeprs Blog
Yes there is a way to get the number of lines occupied by the text in the textbox. It's not that simple though 'coz you have to simulate the behavior of the word wrap in order to count/predict the number of lines generated as a result of a word wrap. I have the solution described here in detail.

Resources