
UserControl.Width / .Height set to incorrect value
I have been trying for some time to get a number of user controls to "mesh"
together on a form; whenever the form is resized the user controls grow and
shrink and move so as to leave to gaps between them. However, I kept getting
these gaps between the controls! The gaps were not really visible with smaller
sized forms, but as the size of the form (and the controls on it) grew, the gaps
became more noticeable until the form looked bad, unprofessional.
So I created a little test project to find out what was wrong.
My project is a standard .EXE project with a single startup form
named "frmMain". There is a single command button named "cmdPrintSize" in the
top left-hand corner. Directly below that is a custom user control
named "MyControlB1". The Width property of MyControlB1 is set to 1000 (Twips)
and the Height property is set to 1000. These properties are set at design time
with the property browser. Here is the complete code for frmMain:
Option Explicit
Private Sub cmdPrintSize_Click()
With MyControlB1
Debug.Print "Control Size: W = " & .Width & ", H = " & .Height
End With
End Sub
MyControlB is a user control with one button named "cmdResize" in the upper left-
hand corner. Here is the code for MyControlB:
Option Explicit
Private Sub cmdResize_Click()
UserControl.ScaleMode = vbTwips
Debug.Print "1) Width = " & CStr(Width)
Debug.Print " Height = " & CStr(Height)
UserControl.Width = 5000
Debug.Print "2) Width = " & CStr(Width)
Debug.Print " Height = " & CStr(Height)
UserControl.Height = 5000
Debug.Print "3) Width = " & CStr(Width)
Debug.Print " Height = " & CStr(Height)
End Sub
Private Sub UserControl_Initialize()
'Make the control easily visible.
UserControl.BackColor = vbRed
End Sub
The project is run and cmdPrintSize is clicked. The output in the Immediate
Window is as expected:
Control Size: W = 1000, H = 1000
Next the cmdResize button on MyControlB1 is clicked. The EXPECTED output is:
1) Width = 1000
Height = 1000
2) Width = 5000
Height = 1000
3) Width = 5000
Height = 5000
The ACTUAL output is:
1) Width = 1001
Height = 1001
2) Width = 4972
Height = 979
3) Width = 4939
Height = 4972
The problem with the first output is that the original Width and Height SHOULD
have been exactly 1000.
There are two problems with the second output. First, the width is set to 4972
when it should be set to 5000. Second, the Height property changed with the
Width.
The same two problems exist with the third output: The Height was SET to 5000
but now reads 4972, and the Width was changed again, from its already incorrect
value of 4939 to an even MORE incorrect value.
If cmdPrintSize on frmMain is now clicked AGAIN, the output is:
Control Size: W = 4972, H = 5005
Yet a DIFFERENT set of values.
The biggest problem of all: I have spent TWO HOURS on the microsoft web sites
without finding a way to file a freakin' bug report without paying money. Start
of tirade. I have used up my free "Incident Submissions" and I am not about to
pay a global software giant to help debug its software for it. This is one of
the reasons programmers such as myself avoid microsoft products like the plauge
when we are working on our school projects and this is why I am extremely
irritated at the necessity of working with microsoft products in my workplace.
CHARGING to file a BUG REPORT?!?!? Paying just to fire off an email to someone?
Any company that felt the pressure of competition in the market would certainly
not require monetary compensation for customer feedback or for an evaulation of
product performance. End of tirade.