Article ID: 175501
Article Last Modified on 6/24/2004
Dim x As String x = RichTextBox2.TextRTF RichTextBox2.TextRTF = x
Option Explicit
Private Sub Command1_Click()
'This line is the core of the problem, loading text
'into an RTF box from a file using LoadFile can cause
'unexpected scroll bar behavior
RichTextBox2.LoadFile ("C:\TestRTF")
'**********************************************
'All the rest of the code is to attempt to set up a demo
'which will reproduce the problem on any screen resolution
'**********************************************
'Create informational text for Label1
Dim Caption2 As String
Caption2 = "The text in the RTF box below is the same as above. "
Caption2 = Caption2 & "It was pulled out of the box above, "
Caption2 = Caption2 & "saved to a file, then loaded into the box "
Caption2 = Caption2 & "below. Notice the absence of a horizontal "
Caption2 = Caption2 & "scroll bar."
Label2.Caption = Caption2
End Sub
Private Sub Command2_Click()
'These three lines of code provide a workaround
Dim x As String
x = RichTextBox2.TextRTF
RichTextBox2.TextRTF = x
End Sub
Private Sub Form_Load()
'Size, position, and set captions for everything
Form1.Height = 5925
Label1.Move 120, 120, 4000, 975
Label2.Move 120, 2640, 4000, 855
Label2.Caption = ""
RichTextBox1.Move 120, 1200, 4000, 1215
RichTextBox2.Move 120, 3600, 4000, 1215
Command1.Move 120, 4920, 1215, 495
Command1.Caption = "Load Text"
Command2.Move 1560, 4920, 1215, 495
Command2.Caption = "Workaround"
'set fonts for Form1 and RichTextBox1
Form1.Font = "Times New Roman"
RichTextBox1.Font = "Times New Roman"
'create informational text for Label
Dim Caption1 As String
Caption1 = "The text that appears below was read in as a string. "
Caption1 = Caption1 & "Notice that the horizontal scroll bar "
Caption1 = Caption1 & "appears. This is because one of the lines "
Caption1 = Caption1 & "of text is wider than the RTFbox"
Caption1 = Caption1 & " (you have to scroll down to see this "
Caption1 = Caption1 & "line).This behavior is expected."
Label1.Caption = Caption1
'populate RichTextBox1 with the most of the text
Dim Msg As String
Msg = "This is to test the horizontal scroll bars "
Msg = Msg & "on the RichTextBox" & vbCrLf
Dim i As Integer
For i = 1 To 20
Msg = Msg & "Scroll Down" & vbCrLf
Next i
'Size the RichTextBoxes to be slightly wider than the
'first line of text and slightly shorter than the last
'line of text
RichTextBox1.Width = Form1.TextWidth(Msg) * 1.1
RichTextBox2.Width = RichTextBox1.Width
'size the form and labels to agree with size of RichTextBoxes
Form1.Width = RichTextBox1.Width + 360
Label1.Width = RichTextBox1.Width
Label2.Width = RichTextBox1.Width
'Add a line to the text that is slightly wider than the
'RichTextBoxes
Msg = Msg & "This is to test the horizontal scroll bars "
Msg = Msg & "on the RichTextBox" & "zzzzz"
'clear RichTextBox2
RichTextBox2.TextRTF = ""
'create an rtf file exactly like the text of the
'first rtfbox
RichTextBox1.TextRTF = Msg
RichTextBox1.SaveFile ("C:\TestRTF")
End Sub
Private Sub Form_Resize()
RichTextBox1.Width = Form1.Width - 360
RichTextBox2.Width = Form1.Width - 360
End Sub
Keywords: kbbug kb32bitonly KB175501