Control Overlaid by Another Control Fails to Refresh if Moved

ID Number: Q74519

1.00

WINDOWS

Summary:

Visual Basic does not support overlapping controls. Having overlapping

controls can result in portions of a control not refreshing correctly.

If controls are moved over each other, then one or both of the

controls may not correctly refresh even when the controls are moved

apart. This is known to happen when controls are resized at run time

using the Move method or by changing the Height and Width properties

as a result of a Form_Resize event. Because controls must be resized

one at a time, it is possible that one control will briefly overlap

another control during the resize process at run time. The control

that was briefly overlapped may not refresh properly. An example of

this behavior is given further below.

This behavior can be improved by performing the Refresh method

(CtrlName.Refresh) on every overlapping control at run time, after an

overlapped control has been moved or after a form that contains

overlapping controls has been resized.

This is not a problem with Visual Basic, but the nature of overlapping

controls under Visual Basic. This behavior occurs at run time in the

Visual Basic development environment or as an .EXE program.

This information applies to the Visual Basic programming system

version 1.0 for Windows.

More Information:

For more information about Visual Basic and overlapping controls,

query in this knowledge base on the following words:

overlapping and controls and Visual and Basic

Steps to Reproduce Problem

--------------------------

1. From the File menu, choose New Project (ALT, F, P).

2. Add a picture control (Picture1) to the default form (Form1).

3. Add a command button (Command1) to Form1.

4. Add a vertical scroll bar (VScroll1) to Form1.

5. Using the mouse, double-click on Form1 to bring up the code

window.

6. Within the Resize event procedure of Form1, add the following code:

Sub Form_Resize ()

Picture1.Move 0, 0, ScaleWidth - VScroll1.Width, _

ScaleHeight - Command1.Height

VScroll1.Move ScaleWidth - VScroll1.Width, 0, _

VScroll1.Width, ScaleHeight - Command1.Height

Command1.Move 0, ScaleHeight - Command1.Height, _

ScaleWidth, Command1.Height

End Sub

Note: The underscores (_) in the above code example indicate that

the line should be concatenated with the next line in the Visual Basic

environment (VB.EXE).

7. Run the program.

8. Using the mouse, resize the form by extending the bottom or right

sides. When the bottom edge of the form is extended, the command

button (Command1) will not refresh. When the right edge of Form1

is extended, the scroll bar will not refresh. The refresh problems

are caused because Picture1 is expanded and temporarily overlaps

the control. When the control (VScroll1 or Command1) is moved out

of the way, it is not refreshed.

To work around this behavior, use the Refresh method for Picture1,

VScroll1, and Command1 after the controls have be moved. Add the

following statements to Sub Form_Resize (after the Command1.Move

statement) above to overcome the behavior:

Picture1.Refresh

VScroll1.Refresh

Command1.Refresh

Additional reference words: 1.00