简体   繁体   English

在Win Form Rich Text Box中的RTL和LTR之间切换时显示问题

[英]displaying issue when switching between RTL and LTR in Win Form Rich Text Box

I tried the same thing in both Win form and WPF form and seems this only happens in Win Form. 我在Win窗体和WPF窗体中都尝试了同样的事情,看来这仅在Win Form中发生。 Basically what's happening is that I have a RTB control in Win Form, and 2 buttons: RTL and LTR to adjust the alignment. 基本上发生的是,我在Win Form中有一个RTB控件,还有2个按钮:RTL和LTR来调整对齐方式。

button1 clicked: button1单击:

richTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;

button2 clicked: button2单击:

richTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.No;

That's all I have. 这就是我的全部。 when I paste text into RTB and click on the RTL button, it left a big gap in RTB. 当我将文本粘贴到RTB中并单击RTL按钮时,它在RTB中留下了很大的空白。 I noticed this will ONLY happen if the scroll bar is presenting. 我注意到只有在显示滚动条时才会发生这种情况。 if you resize the form, the gap will go away. 如果您调整窗体的大小,差距将消失。

see link for the screenshot: screenshot of the issue 查看屏幕快照的链接: 问题的屏幕截图

I tried everything I could but couldn't figure out why it's happening. 我尽了一切努力,但不知道为什么会这样。 I suspect it's a .NET bug, does anybody have any idea? 我怀疑这是一个.NET错误,有人知道吗?

The only solution I could get to work is to reset the text when you change the RightToLeft property of the RTB control and adding a Application.Doevents(). 我唯一可以使用的解决方案是在更改RTB控件的RightToLeft属性并添加Application.Doevents()时重置文本。

Like this: 像这样:

private void buttonRTL_Click(object sender, EventArgs e)
{

    string txtRTF = RichTextBox1.Rtf;
    RichTextBox1.Clear();
    RichTextBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
    Application.DoEvents();
    RichTextBox1.Rtf = txtRTF;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM