Microsoft KB Archive/271695

= PRB: Picture in MDI Form Does Not Display =

Article ID: 271695

Article Last Modified on 5/13/2003

-

APPLIES TO


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

-



This article was previously published under Q271695



SYMPTOMS
When programmatically setting the picture property of a multiple-document interface (MDI) Form, the picture may not be displayed, or may be partially rendered when an MDIChild form is dragged inside the MDI Form.

This behavior does not occur in Microsoft Visual Basic 5.0.



RESOLUTION
Use the RedrawWindow API function to redraw the MDI Form after the picture assignment.



Steps to Reproduce Behavior
 Create a Visual Basic 6.0 Standard EXE project. Form1 is created by default. On the Properties window, set following properties for Form1:

MDIChild = True

 On the Project menu, click Add MDIForm to add a MDI Form. On the Properties window, set following properties for MDIForm1:

WindowState = 2 - Maximized

  on the Project menu, select Properties. On the General tab, select MDIForm1 as the Startup Object, and then modify MDIForm1's Load event as follows: Private Sub MDIForm_Load 'Show the Child Form Form1.Show End Sub   Add a CommandButton to Form1. Modify the button's click event as follows: Private Sub Command1_Click 'Assign picture MDIForm1.Picture = LoadPicture(&quot;c:\winnt\winnt.bmp&quot;) End Sub </li> Start the application, and then drag Form1 from its default position toward the center of the screen.</li> Click the CommandButton on Form1, and note that no picture appears. The expected behavior is that the picture appears if you drag Form1 to the top-left corner of MDIForm1.</li></ol>

Workaround
In order to work around this behavior, you can call RedrawWindow after assigning a picture to the MDIForm's picture property. This causes the MDIForm to redraw and display the picture. <ol> On the Project menu, click Add Module to add a new module to the project.</li>  Paste the following code into the new module: Public Declare Function RedrawWindow Lib &quot;user32&quot; (ByVal hWnd As Long, lprcUpdate As Any, _ ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long Public Const RDW_ALLCHILDREN = &H80 Public Const RDW_ERASE = &H4 Public Const RDW_INVALIDATE = &H1 Public Const RDW_UPDATENOW = &H100 </li>  Modify the Command_Click Event on Form1 thus: Private Sub Command1_Click 'Assign picture MDIForm1.Picture = LoadPicture(&quot;c:\winnt\winnt.bmp&quot;) 'Redraw Window Call RedrawWindow(MDIForm1.hWnd, ByVal 0&, 0&, _         RDW_ERASE Or RDW_INVALIDATE Or RDW_ALLCHILDREN Or RDW_UPDATENOW) End Sub </li> Start the application, and then drag Form1 toward the center of the screen.</li> Click the Command Button on Form1, and note that the picture is displayed.</li></ol>

Keywords: kbprb KB271695

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.