Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/171501

From BetaArchive Wiki

Article ID: 171501

Article Last Modified on 12/10/2003



APPLIES TO

  • Microsoft Visual Basic 5.0 Control Creation Edition
  • 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 Q171501

SYMPTOMS

When using a Frame or a PictureBox as its container at run-time, a user- created ActiveX control will move when its width or height is changed. However, the problem does not occur when a Form is used as the container or when the control is placed in the container at design-time.

CAUSE

UserControl caches the window handle it was activated on. When the size is changed, it tries to figure out its current coordinates within its parent by getting its screen coordinates and then mapping them relative to its parent's screen coordinates. Because its cached parent is no longer its real parent, it calculates the wrong coordinates and moves the control to those wrong coordinates.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Studio 97 Service Pack 2.

For more information on the Visual Studio 97 Service Pack 2, please see the following article in the Microsoft Knowledge Base:

170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why


For a list of the Visual Basic 5.0 bugs that were fixed in the Visual Studio 97 Service Pack 2, please see the following article in the Microsoft Knowledge Base:

171554 INFO: Visual Basic 5.0 Fixes in Visual Studio 97 Service Pack 2


MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new ActiveX Control project. UserControl1 is created by default.
  2. Set some of UserControl1's properties to the following:

    ScaleMode = 3 - Pixel
    Backcolor = Blue or some color other than gray

  3. Close UserControl1. It now appears in the Toolbox.
  4. Select Add Project from the File menu and add a Standard EXE. Form1 is created by default.
  5. Place the following controls on Form1:

          Two CommandButton controls(Command1 and Command2);
          One PictureBox (Picture1);
          One UserControl1(UserControl11) that was just created;
                            

    NOTE: Make Picture1 large and UserControl11 small so that the undesired behavior is more obvious.

  6. Set Picture1's ScaleMode to 3 - Pixel.
  7. Insert the following code to Command1's Click event procedure:

          Set UserControl11.Container = Picture1
          UserControl11.Top = 0
          UserControl11.Left = 0
                            
  8. Insert the following code to Command2's Click event procedure:

          UserControl11.Top = 0
          UserControl11.Left = 0
          UserControl11.Width = UserControl11.Width + 30
                            
  9. Press the F5 key to run the application
  10. Click on Command1 first. Usercontrol11 should be placed inside the Picture1.
  11. Click on Command2. UserControl11 should increase its width. It also moves in Picture1.


Keywords: kbbug kbfix kbvbp500sp2fix kbvs97sp2fix KB171501