BUG: Repositioning or Resizing a Control After Changing the Font Causes Incorrect Positioning and Sizing (206907)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 5.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 5.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q206907

SYMPTOMS

When you programmatically reposition and resize a control to a new scale immediately after the Font property of the control has been changed, the control's new size and new position may be incorrect.

RESOLUTION

Change the control's position and size properties before changing the control's Font property.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open a new Visual Basic Standard EXE project. Form1 is created by default.
  2. Add two Label controls, two TextBox controls, and two CommandButton controls to Form1.
  3. Add the following code to the General Declarations section of Form1:
    Option Explicit
    Private Sub form_load()
      Label1.Left = 120
      Label1.Top = 255
      Label1.Height = 255
      Label1.Width = 615
      
      Label2.Left = 120
      Label2.Top = 615
      Label2.Height = 255
      Label2.Width = 615
     
      Text1.Left = 840
      Text1.Top = 240
      Text1.Height = 285
      Text1.Width = 1215
      
      Text2.Left = 840
      Text2.Top = 600
      Text2.Height = 285
      Text2.Width = 1215
      
      Command1.Left = 2160
      Command1.Top = 240
      Command1.Height = 285
      Command1.Width = 2175
      Command1.Caption = "Change Font Then Scale"
      
      Command2.Left = 2160
      Command2.Top = 600
      Command2.Height = 285
      Command2.Width = 2175
      Command2.Caption = "Change Scale Then Font"
        
      Form1.Left = 0
      Form1.Top = 0
      Form1.Height = 1560
      Form1.Width = 4605
    End Sub
    
    Private Sub Command1_Click()
        ChangeFont
        ChangeScale
    End Sub
    
    Private Sub Command2_Click()
        ChangeScale
        ChangeFont
    End Sub
    
    Private Sub ChangeFont()
        Dim fntNew As StdFont
        Dim oControl As Object
        
        Set fntNew = New StdFont
        With fntNew
            .Name = "MS Sans Serif"
            .Size = 14
        End With
        
        On Error Resume Next
        For Each oControl In Me.Controls
            Set oControl.Font = fntNew
        Next
    End Sub
    
    Private Sub ChangeScale()
        Const FactorX = 1.77
        Const FactorY = 1.85
        
        Dim oControl As Object
        
        On Error Resume Next
        With Me
            .Move 0, 0, .Width * FactorX, .Height * FactorY
            For Each oControl In .Controls
                With oControl
                    .Left = .Left * FactorX
                    .Top = .Top * FactorY
                    .Width = .Width * FactorX
                    .Height = .Height * FactorY
                End With
            Next
        End With
    End Sub
    					
  4. Run the program. Click the CommandButton labeled Change Font Then Scale. The form displays incorrectly. The controls are not sized properly. In addition, the TextBoxes overlap and the CommandButtons butt up against each other.
  5. Exit the program, and then run the program again. Click the CommandButton labeled Change Scale Then Font, and note that the problem does not occur.

REFERENCES

For additional information on rescaling forms, click the article number below to view the article in the Microsoft Knowledge Base:

182070 HOWTO: Create a Resolution-Independent Form


Modification Type:MajorLast Reviewed:10/15/2002
Keywords:kbBug kbDSupport KB206907