Multiline Textbox Vertical Spacing (Winform) - winforms

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.

Related

How does one find the caret position (in screen-space or form-space) in a WPF textbox?

As the title suggests, how do I find the caret position of a WPF textbox in screen or form-space coordinates? So far, I've only been able to find how to get the character position of the caret in the textbox.
Perhaps I'm getting ahead of myself though, because really, I'm trying to ensure that the current caret position of the selected TextBox (of dynamic height) contained within a DataGrid is visible to the user. So, if there's a way to do this without knowing the coordinates of the caret, then I'm all ears. So far, I've tried calling the DataGrid's ScrollIntoView method, but this can fail if the TextBox is taller than the available screen space.
I don't believe you can do it natively, but you call use interop to call the Win32 GetGUIThreadInfo(). See here for an example: How to call GetGUIThreadInfo in c#
I would suggest something but I don't know if it is applicable in your case. I needed to create a triangular caret to replace the vertical-line caret of a WPF textbox. I control its location with a translate transform and it is always following the default textbox caret. In this way you know where is your new caret is inside the text box (by knowing the X and Y of its translate transform) and then you can use PointToScreen to convert it to screen coordinates.

How to make a RichTextBox automatically resize horizontally & vertically and make its parent resize as well?

I need to put a RichTextBox inside a container such as a canvas/grid/stackpanel or anything which serves the purpose best.
look at the example I made:
in the picture RichTextBox is white, Canvas is LightBlue, and the main window's Grid is salmon(=light orange)
The user starts typing inside the RichTextBox. as far as he DOESN'T press enter or shift+enter, the RichTextBox must resize horizontally as long as the sentence is, on the condition that it doesn't exceed the main grid's boundaries.
RichTextBox must also resize vertically, when the user starts typing in new lines, but should not exceed the grid's boundaries.
So how is it done ?
This is not the best aproach that you looking for but i't works...
Just increase the Document.PageWidth based on the content inside the textbox by doing this
richTextBox1.Document.PageWidth = 1000;
However, consider looking for No Wrap for the richtext box. Wich i'm out of time to give more help.

How to correct Winforms Treeview horizontal scrollbars with owner drawn nodes?

I am creating a custom winforms Treeview that is completely owner drawn. When a bolded text node is drawn and reaches beyond the width of the Treeview, the text is cutoff because the horizontal scrollbar cannot scroll any further. I assume it has something to do with the bold text and it can't figure out the correct width. Is there a way to correct the scrollbar, so that it can scroll all the way.
There is no clean fix for this, the native Windows treeview control is missing a "MeasureNode" kind of message. Which would be required to give the horizontal scrollbar the proper range if you custom-draw a wider string. So, inevitably, it is still based on the size of the TreeNode.Text string.
There's a dirty fix for this, it works but is unpleasant. You do it by giving the TreeNode.Text property a fake string, wide enough to whack the scrollbar in shape. And use, say, the Tag property to store the real string you want to draw. Ugly but effective hack. Unpleasant because you cannot easily hide that code.

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 render whitespaces as dots in WPF RichTextBox?

I need the way to render regular space, nonbreaking space and some other formatting characters (like left-to-right mark) like MS Word renders them, when you choose to show non-printable characters.
I tried two approaches:
1) Replace characters with rarely used characters.
It works, but in this case we loose "nonbreaking" behavior of nonbreakable space (and LTR and RTL marks also stop working)
2) Use the custom font
It allows to preserve special behavior of nonbreaking space and LTR/RTL marks, but for some strange reason WPF renders nonbreaking space with usual space glyph.
WinForms RichTextBox renders text with the same font correctly.
This problem could be solved with applying different font with different space glyph for spaces and nonbreaking spaces, but LTR and RTL marks are not rendered at all even if I add glyph for them.
Have you any ideas how I could render that characters with visible glyph preserving their "LTR", "RTL", "nonbreaking" behavior?
I didn't try anything similar until now, but I can think of two options:
Warning -> I didn't try it out
The first method:
Create a subclass of UIElement
Get the Style with ControlTemplate for the Richtextbox and add it to App.xaml
Add an instance of your subclassed UIElement within the inner Panel of the Scrollviewer from the RichTextBox ControlTemplate
Make the RTBox available to a dependency property in your class via DataBinding in the ControlTemplate (if possible) or any other way that does the job
In your UIElement subclass, you iterate through characters of the document
Draw a symbol in your Adorner for each space and LineBreak you encounter
Get the Rect of a character at a specific position with the RichTextBox. Use this rect for placing the symbols.
The advantage of this Method is that you have a clean separation and don't need to subclass the RTFBox, but you won't be able manipulate the width of the spacing to make room for larger symbols. Also, other developers need to know that they need that Style in order to gain that functionality.
The second method:
Create a Custom Adorner
Decorate the RTBox with the custom Adorner
From the Adorner, you should be able to access the Child RTBox
In your UIElement subclass, you iterate through characters of the document
Draw a symbol in your UIElement for each space and LineBreak you encounter
I remember that there is a possibility to get the Rect of a character at a specific position with the RichTextBox. Use this rect for placing the symbols.
It's also without subclassing the RTBox. You also can't adjust the spacing. In contrast to method 1, other developers will immediatly recognize that this functionality has been added. The one disadvantage is that you will have to handle scrolling too.
You can try insert near LTR/RTL visible glyph instead of replace that.
Store all of the values as their special characters. It sounds like your printing functions need to handle a) what kind of output the user wants, b) interpret your data array/massive string of characters and spit out the values with regard to what the user wants to see. You don't give too many details on how your things are stored but this would be a very reasonable way to go about things.

Resources