UserControl.Width / .Height set to incorrect value 
Author Message
 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.



Tue, 18 Nov 2003 07:27:02 GMT  
 UserControl.Width / .Height set to incorrect value
Maybe... the Align to Grid setting is checked in the
VB options page.  Try un-checking it.

D.


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.



Tue, 18 Nov 2003 07:45:45 GMT  
 UserControl.Width / .Height set to incorrect value
No, that didn't change anything.  But thanks for trying. :)

-Forrest

Quote:
-----Original Message-----

Maybe... the Align to Grid setting is checked in the
VB options page.  Try un-checking it.

D.



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.

.



Tue, 18 Nov 2003 08:08:00 GMT  
 UserControl.Width / .Height set to incorrect value
UserControl.ScaleMode = vbTwips
'333 is the number of pixels wide/high this usercontrol will be
UserControl.Width = CDbl(333 * Screen.TwipsPerPixelX)
UserControl.Height = CDbl(333 * Screen.TwipsPerPixelY)

This code was placed in the usercontrol command button
click event..

I'm going to guess that you can't make something size size
itself so that it falls on a width that is a partial pixed wide or
high.

That said...  333 pixels is 4995 twips.  334 pixels is 5010 twips.
...you'll have to settle on one of those sizes.

So
? screen.TwipsPerPixelX
 15
? screen.TwipsPerPixely
 15
it looks like you'll have to jig with the .left position of the second
control to get them to {*filter*}up perfectly...

D.


No, that didn't change anything.  But thanks for trying. :)

-Forrest

Quote:
-----Original Message-----

Maybe... the Align to Grid setting is checked in the
VB options page.  Try un-checking it.

D.



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.

.



Tue, 18 Nov 2003 08:39:14 GMT  
 UserControl.Width / .Height set to incorrect value
YES you can

I have incountered this SAME EXACT BUG in the past.

I'm guessing you are trying to change the width/height during
UserControl_Initalize

AFTER intalize, the height and width is adjusted AGAIN by the cashed
properties of it's container.

Workaround:

(NOTE: your datetypes should be single, not double...)

Place somthing like the following in the UserControl_Resize Event

Private sub UserControl_Resize
    Dim HH as single, WW as single
    HH = cSng(333 * Screen.TwipsPerPixelX)
    WW = cSng(333 * Screen.TwipsPerPixelY)

    if (UserControl.Width<> WW) then
         UserControl.Width = WW
    end if
    if (UserControl.Height<> HH) then
         UserControl.Height = HH
    end if
end sub

The reson for TESTING first, seting the height/width ussually causes a
imeadiate call back to Usercontrol_Resize.  Fail to test, and you get
recursion untill a stack-overflow error is generated.

HTH


Quote:
> UserControl.ScaleMode = vbTwips
> '333 is the number of pixels wide/high this usercontrol will be
> UserControl.Width = CDbl(333 * Screen.TwipsPerPixelX)
> UserControl.Height = CDbl(333 * Screen.TwipsPerPixelY)

> This code was placed in the usercontrol command button
> click event..

> I'm going to guess that you can't make something size size
> itself so that it falls on a width that is a partial pixed wide or
> high.

> That said...  333 pixels is 4995 twips.  334 pixels is 5010 twips.
> ...you'll have to settle on one of those sizes.

> So
> ? screen.TwipsPerPixelX
>  15
> ? screen.TwipsPerPixely
>  15
> it looks like you'll have to jig with the .left position of the second
> control to get them to {*filter*}up perfectly...

> D.



> No, that didn't change anything.  But thanks for trying. :)

> -Forrest

> -----Original Message-----
> Maybe... the Align to Grid setting is checked in the
> VB options page.  Try un-checking it.

> D.



> 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.

> .



Wed, 19 Nov 2003 02:50:21 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Setting form width/height = image width/height

2. Setting Usercontrol (ocx) width at runtime wider than Width property of usercontrol

3. Set MDI width and Height to minimum values

4. picture object height and width are incorrect.

5. Usercontrol with fixed width and height

6. HELP: Initial height/width of UserControl varies

7. Setting page height/width and shape IDs

8. Setting the Min/Max Width/Height of a form in VB6

9. How to set Me.Width and Me.Height in one step

10. Help on setting a fix height and width editing box

11. Setting minimum width and height of form

12. HELP ! Need to set Printer Height and Width

 

 
Powered by phpBB® Forum Software