dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.3k stars 955 forks source link

Add Justified HorizontalAlignment for RichTextBox #10792

Open lr-devx opened 5 months ago

lr-devx commented 5 months ago

Background and motivation

I noticed that RTF documents support Justified alignment, yet RichTextBoxes do not provide the ability to set that alignment for some reasons.

API Proposal

    public enum HorizontalAlignment
    {
        Left = 0,
        Right = 1,
        Center = 2,
        Justified = 3
    }

API Usage

RichTextBox richTextBox = new RichTextBox();
richTextBox.SelectionAlignment = HorizontalAlignment.Justified;

Alternative Designs

No response

Risks

None.

Will this feature affect UI controls?

It should be supported by the designer. It won't have any impact on accessibility. And obviously it doesn't need to be localized.

elachlan commented 5 months ago

HorizontalAlignment isn't only used by RichEdit, its used by many other controls.

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.horizontalalignment?view=windowsdesktop-8.0#remarks

This enumeration is used in numerous classes. A partial list of these classes is CheckedListBox, ColumnHeader, ComboBox, ControlPaint, Label, ListBox, Control, RichTextBox, and TextBox.

If we look at the underlying docs for win32: https://learn.microsoft.com/en-us/windows/win32/api/richedit/ns-richedit-paraformat2_1

image

So it is supported in win32 and exists in our interop code: https://github.com/dotnet/winforms/blob/aa582c48802a1ae97ee766cf9087fdc85f9bbd0e/src/System.Windows.Forms.Primitives/src/Interop/Richedit/Interop.PFA.cs#L6-L15

I think it might require an investigation into each consumer of HorizontalAlignment and see if its supported on all the controls. If not, then a new enum would possibly be required.

lr-devx commented 5 months ago

(Whops) In that case it would make more sense to create a new enumeration, something like "TextAlignment" IMO

elachlan commented 5 months ago

I'd suggest ParagraphAlignment because it closely aligns with the docs.

@merriemcgaw this would be a breaking change. Is it unlikely to be accepted?

merriemcgaw commented 5 months ago

Yeah, I'm afraid if this is any sort of breaking change it would be unlikely to be accepted. Let's add the untriaged label and it can get discussed with the broader team, but I'd keep expectations somewhat lower.

SteveAndrews commented 1 month ago

@merriemcgaw What about adding a new property with the new enumeration and [Obsolete] the old property?

merriemcgaw commented 1 month ago

@SteveAndrews we could create a second property to manage this, I don't know if we'd obsolete the original property though it sounds like we could make a non-breaking way to do this.

That said, I don't believe this will bubble up far enough priority-wise to make it to .NET 9. We can keep this on our radar for .NET 10 because properly done I can see how it would benefit richedit customers.