BUG: Cannot Set RichTextBox Visible Property to False

ID: Q189483


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0


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.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Standard EXE project. Form1 is created by default.


  2. From the Project menu, click Components, and check the "Microsoft Rich Textbox Control."


  3. 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 


  4. 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.


  5. Remove the comment from the ShowWindow call and run the sample again. Notice that the problem no longer occurs.



REFERENCES

For more information please see the following article in the Microsoft Knowledge Base:

Q149463 RichTextBox Appears Even If Visible Property is False

Additional query words: kbDSupport kbDSD kbVBp kbCtrl kbvbp400bug kbVBp500bug

Keywords : kbGrpVB
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: January 5, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.