带有预加载文本的RightToLeft RichTextBox

时间:2012-06-04 13:48:36

标签: vb.net richtextbox

好的,我在vb.net 2008中的MS默认Richtextbox中发现了一种奇怪的错误。如果我们在程序设计中在Richtextbox中添加一些文本行。右侧有一个瞪口。见下图

ٰerror

这是我的代码

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim f As New Form
    Dim rtb As New RichTextBox
    f.Width = 500
    f.Height = 500
    rtb.RightToLeft = Windows.Forms.RightToLeft.Yes
    For i = 1 To 20
        rtb.AppendText("بسم اللہ الرحمن الرحیم" & vbNewLine)
    Next
    rtb.Dock = DockStyle.Fill
    f.Controls.Add(rtb)
    f.Show()
End Sub

2 个答案:

答案 0 :(得分:1)

我无法解释,但尝试更改代码的顺序,以便在附加文本之前将RichTextBox控件添加到表单中。这对我有用:

Private Sub btn1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn1.Click
  Dim f As New Form
  f.Width = 500
  f.Height = 500

  Dim rtb As New RichTextBox
  rtb.Name = "rtb"
  rtb.Dock = DockStyle.Fill
  rtb.RightToLeft = RightToLeft.Yes

  f.Controls.Add(rtb)
  For i = 1 To 25
    rtb.AppendText("بسم اللہ الرحمن الرحیم" & vbNewLine)
  Next
  f.Show()

  f.BeginInvoke(New Action(Of RichTextBox)(AddressOf RunFix), rtb)
End Sub

Sub RunFix(ByVal rtfControl As RichTextBox)
  rtfControl.Select(0, 0)
  rtfControl.ScrollToCaret()
End Sub

我添加了一个hack BeginInvoke方法来执行ScrollToCaret()调用似乎来解决问题。

答案 1 :(得分:0)

如果你也设置了

rtb.Width = 500
rtb.Height = 500

然后它按预期工作。

我同意这是奇怪的行为。它与VS 2012 RC一样。