0

When compared the text alignment with RichTextBox, behavior has changed from .Net4.6.1 to .Net4.8.

Any help on how the earlier behavior of .Net 4.6.1 can be achieved in .Net4.8?

enter image description here

public Form1()
    {
        InitializeComponent();

        
        RichTextBox richTextBox1 = new RichTextBox()
        {
            Width = 300,
            Height = 20,
            Location = new Point(100, 100)
        };

        richTextBox1.Text = "中文_Dummy_Text";

        TextBox textBox = new TextBox()
        {
            Width = 300,
            Height = 20,
            Location = new Point(100, 200)
        };

        textBox.Text = "中文_Dummy_Text";

        this.Controls.Add(richTextBox1);
        this.Controls.Add(textBox);

    }
3
  • There was a big change in .NET 4.7, this code was added to Winforms. Yet another one without attribution :( You can get the old one back with cp.ClassName = "RichEdit20W"; But realistically this is a simple mistake, just increase the Height a bit so the text can fit. Aug 19, 2020 at 11:52
  • @HansPassant - This issue occurs when text contains fonts like chinese/japanese. But when Text is only of english font then there is no issue.So adjusting height will have problem in current working scenarios. Aug 19, 2020 at 13:49
  • @HansPassant tried code snippet you mentioned but with no success. however, I could see cp.className is already "RichEdit50W" Aug 19, 2020 at 13:56

2 Answers 2

2

Adding the runtime setting in App.Config (as below) reverted back to the older RTB in .NET 4.8.

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
        </startup>
      <runtime>
         <AppContextSwitchOverrides value="Switch.System.Windows.Forms.DoNotLoadLatestRichEditControl=true"/>
      </runtime>
    
    </configuration>
0

Setting multiline property to false also restores the earlier behavior of RTB

richTextBox1.Multiine = false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.