Microsoft KB Archive/189483

= BUG: Cannot Set RichTextBox Visible Property to False =

Article ID: 189483

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q189483



SYMPTOMS
Setting the Visible property of a Rich TextBox control to False does not hide the control after using the Span method of that control.



RESOLUTION
To work around this problem, add a call to the ShowWindow API function, passing the SW_HIDE constant after setting the Visible property of the Rich Textbox to False. This can be tested by uncommenting the following line in the sample code in the MORE INFORMATION section below: result = ShowWindow(RichTextBox1.hwnd, SW_HIDE)



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start a new Standard EXE project. Form1 is created by default. From the Project menu, click Components, and check the "Microsoft Rich Textbox Control."  Place a Rich Textbox Control along with three CommandButtons onto Form1, and add the following code to the form's module: Private Declare Function ShowWindow Lib "user32" _ (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Const SW_HIDE = 0

Private Sub Form_Load Command1.Caption = "Span and Hide" Command2.Caption = "Hide" Command3.Caption = "Show" End Sub

Private Sub Command1_Click Dim result As Long

Debug.Print "Before Span: Visible = " & RichTextBox1.Visible RichTextBox1.Span ".?!:", True, True ' Select to the end Debug.Print "After Span: Visible = " & RichTextBox1.Visible RichTextBox1.Visible = False '************        ' Uncomment the following line to hide the Rich TextBox ' result = ShowWindow(RichTextBox1.hwnd, SW_HIDE) '************        Debug.Print "After set Visible to False: Visible = " & _ RichTextBox1.Visible End Sub

Private Sub Command2_Click RichTextBox1.Visible = False End Sub

Private Sub Command3_Click RichTextBox1.Visible = True End Sub  Run the project and click "Span and Hide" twice. Notice that the Rich TextBox is visible despite the fact it's Visible property is explicitly set to False. Remove the comment from the ShowWindow call and run the sample again. Notice that the problem no longer occurs.</ol>

<div class="references_section">