Dynamically move/resize controls on resized form 
Author Message
 Dynamically move/resize controls on resized form

I am trying to write an event procedure to dynamically move & resize the
controls on a form when the form itself is resized.  My form has one large
listbox with a row of buttons underneath.  Basically I just want to resize
the listbox so that it fills most of the window, and move the buttons so
that they stay just above the bottom of the window.  Here's my code:

Private Sub Form_Resize()
    Dim ctl As Control
    lstStudents.Width = Me.InsideWidth - (0.25 * 1440)
    lstStudents.Height = Me.InsideHeight - (0.8 * 1440)
    For Each ctl In Me.Controls
        If ctl.ControlType = acCommandButton Then
            ctl.Top = Me.InsideHeight - (0.375 * 1440)
        End If
    Next
End Sub

Using this code I can resize horizontally just fine.  However, the problem
is that if I resize the form vertically past a certain point, I get
"Run-time error '2100': The control or subform control is too large for this
location" on the line setting ctl.Top = me.InsideHeight - (0.375 * 1440).
The bizarre thing is that the actual Me.InsideHeight threshold past which I
get this error is inconsistent.  Sometimes it's very low (like 5700 twips),
other times its much higher (like 9000 twips).  Any ideas?



Mon, 19 Jan 2004 09:18:47 GMT  
 Dynamically move/resize controls on resized form
I don't see anything obviously wrong.  Did you try setting a
breakpoint on the first statement and stepping through the code?  I
bet the problem would become clear, whatever it is.



Quote:
>I am trying to write an event procedure to dynamically move & resize the
>controls on a form when the form itself is resized.  My form has one large
>listbox with a row of buttons underneath.  Basically I just want to resize
>the listbox so that it fills most of the window, and move the buttons so
>that they stay just above the bottom of the window.  Here's my code:

>Private Sub Form_Resize()
>    Dim ctl As Control
>    lstStudents.Width = Me.InsideWidth - (0.25 * 1440)
>    lstStudents.Height = Me.InsideHeight - (0.8 * 1440)
>    For Each ctl In Me.Controls
>        If ctl.ControlType = acCommandButton Then
>            ctl.Top = Me.InsideHeight - (0.375 * 1440)
>        End If
>    Next
>End Sub

>Using this code I can resize horizontally just fine.  However, the problem
>is that if I resize the form vertically past a certain point, I get
>"Run-time error '2100': The control or subform control is too large for this
>location" on the line setting ctl.Top = me.InsideHeight - (0.375 * 1440).
>The bizarre thing is that the actual Me.InsideHeight threshold past which I
>get this error is inconsistent.  Sometimes it's very low (like 5700 twips),
>other times its much higher (like 9000 twips).  Any ideas?



Mon, 19 Jan 2004 10:14:43 GMT  
 Dynamically move/resize controls on resized form
I have no idea what InsideHeight is (something particular to office?) but
this works in VB, assuming the current scalemode is twips ...
Private Sub Form_Resize()

   Dim ctl As Control
   lstStudents.Width = Me.ScaleWidth - (lstStudents.Left * 2)
   lstStudents.Height = Me.ScaleHeight - (lstStudents.Top * 2) -
Command1.Height

   For Each ctl In Me.Controls
       If TypeOf ctl Is CommandButton Then
         ctl.Top = lstStudents.Top + lstStudents.Height + 100
       End If
   Next

End Sub

--

Randy Birch
MVP Visual Basic

http://www.mvps.org/vbnet/

Please respond only to the newsgroups so all can benefit.


: I am trying to write an event procedure to dynamically move & resize the
: controls on a form when the form itself is resized.  My form has one large
: listbox with a row of buttons underneath.  Basically I just want to resize
: the listbox so that it fills most of the window, and move the buttons so
: that they stay just above the bottom of the window.  Here's my code:
:
: Private Sub Form_Resize()
:     Dim ctl As Control
:     lstStudents.Width = Me.InsideWidth - (0.25 * 1440)
:     lstStudents.Height = Me.InsideHeight - (0.8 * 1440)
:     For Each ctl In Me.Controls
:         If ctl.ControlType = acCommandButton Then
:             ctl.Top = Me.InsideHeight - (0.375 * 1440)
:         End If
:     Next
: End Sub
:
: Using this code I can resize horizontally just fine.  However, the problem
: is that if I resize the form vertically past a certain point, I get
: "Run-time error '2100': The control or subform control is too large for
this
: location" on the line setting ctl.Top = me.InsideHeight - (0.375 * 1440).
: The bizarre thing is that the actual Me.InsideHeight threshold past which
I
: get this error is inconsistent.  Sometimes it's very low (like 5700
twips),
: other times its much higher (like 9000 twips).  Any ideas?
:
:
:
:



Mon, 19 Jan 2004 10:26:32 GMT  
 Dynamically move/resize controls on resized form
Matt, I don't see anything wrong with your logic (assuming
that no button is >= 3/8ths of an inch high) so I'm just
guessing here.

Personally, I don't like to spend so much time in the Resize
event.  I get the feeling(?) that it loses track of
something as the resize event can be triggered very rapidly.
A way to simplify this case would be to move the buttons to
the form's footer so you don't have to recalculate their
position.  Of course, you would have to modify the
expression for the list box height like this:

lstStudents.Height = Me.InsideHeight - (0.8 * 1440) -
Me.Section(2).Height

Marsh

Quote:

>I am trying to write an event procedure to dynamically move
& resize the
>controls on a form when the form itself is resized.  My
form has one large
>listbox with a row of buttons underneath.  Basically I just
want to resize
>the listbox so that it fills most of the window, and move
the buttons so
>that they stay just above the bottom of the window.  Here's
my code:

>Private Sub Form_Resize()
>    Dim ctl As Control
>    lstStudents.Width = Me.InsideWidth - (0.25 * 1440)
>    lstStudents.Height = Me.InsideHeight - (0.8 * 1440)
>    For Each ctl In Me.Controls
>        If ctl.ControlType = acCommandButton Then
>            ctl.Top = Me.InsideHeight - (0.375 * 1440)
>        End If
>    Next
>End Sub

>Using this code I can resize horizontally just fine.

However, the problem
Quote:
>is that if I resize the form vertically past a certain
point, I get
>"Run-time error '2100': The control or subform control is
too large for this
>location" on the line setting ctl.Top = me.InsideHeight -
(0.375 * 1440).
>The bizarre thing is that the actual Me.InsideHeight

threshold past which I

- Show quoted text -

Quote:
>get this error is inconsistent.  Sometimes it's very low
(like 5700 twips),
>other times its much higher (like 9000 twips).  Any ideas?



Mon, 19 Jan 2004 12:20:04 GMT  
 Dynamically move/resize controls on resized form
Hi-
    Try this class-
http://www.levasseur.net/VB/classes/cSizer.cls
(Example usage at the top....)
Joe
--
***************************************************************

 Author of Yankee Clipper III. http://www.yankee-clipper.net
 Windows? clipboard enhancer. ZDNet Editors Five Star Pick.
 Voted "PricelessWare" by the users of alt.comp.freeware.
***************************************************************


Quote:
> I am trying to write an event procedure to dynamically move & resize the
> controls on a form when the form itself is resized.  My form has one large
> listbox with a row of buttons underneath.  Basically I just want to resize
> the listbox so that it fills most of the window, and move the buttons so
> that they stay just above the bottom of the window.  Here's my code:

> Private Sub Form_Resize()
>     Dim ctl As Control
>     lstStudents.Width = Me.InsideWidth - (0.25 * 1440)
>     lstStudents.Height = Me.InsideHeight - (0.8 * 1440)
>     For Each ctl In Me.Controls
>         If ctl.ControlType = acCommandButton Then
>             ctl.Top = Me.InsideHeight - (0.375 * 1440)
>         End If
>     Next
> End Sub

> Using this code I can resize horizontally just fine.  However, the problem
> is that if I resize the form vertically past a certain point, I get
> "Run-time error '2100': The control or subform control is too large for
this
> location" on the line setting ctl.Top = me.InsideHeight - (0.375 * 1440).
> The bizarre thing is that the actual Me.InsideHeight threshold past which
I
> get this error is inconsistent.  Sometimes it's very low (like 5700
twips),
> other times its much higher (like 9000 twips).  Any ideas?



Mon, 19 Jan 2004 19:53:25 GMT  
 Dynamically move/resize controls on resized form
Of course!  It's so obvious.  Put the buttons on the footer...

Thanks.


Quote:
> Matt, I don't see anything wrong with your logic (assuming
> that no button is >= 3/8ths of an inch high) so I'm just
> guessing here.

> Personally, I don't like to spend so much time in the Resize
> event.  I get the feeling(?) that it loses track of
> something as the resize event can be triggered very rapidly.
> A way to simplify this case would be to move the buttons to
> the form's footer so you don't have to recalculate their
> position.  Of course, you would have to modify the
> expression for the list box height like this:

> lstStudents.Height = Me.InsideHeight - (0.8 * 1440) -
> Me.Section(2).Height

> Marsh


> >I am trying to write an event procedure to dynamically move
> & resize the
> >controls on a form when the form itself is resized.  My
> form has one large
> >listbox with a row of buttons underneath.  Basically I just
> want to resize
> >the listbox so that it fills most of the window, and move
> the buttons so
> >that they stay just above the bottom of the window.  Here's
> my code:

> >Private Sub Form_Resize()
> >    Dim ctl As Control
> >    lstStudents.Width = Me.InsideWidth - (0.25 * 1440)
> >    lstStudents.Height = Me.InsideHeight - (0.8 * 1440)
> >    For Each ctl In Me.Controls
> >        If ctl.ControlType = acCommandButton Then
> >            ctl.Top = Me.InsideHeight - (0.375 * 1440)
> >        End If
> >    Next
> >End Sub

> >Using this code I can resize horizontally just fine.
> However, the problem
> >is that if I resize the form vertically past a certain
> point, I get
> >"Run-time error '2100': The control or subform control is
> too large for this
> >location" on the line setting ctl.Top = me.InsideHeight -
> (0.375 * 1440).
> >The bizarre thing is that the actual Me.InsideHeight
> threshold past which I
> >get this error is inconsistent.  Sometimes it's very low
> (like 5700 twips),
> >other times its much higher (like 9000 twips).  Any ideas?



Tue, 20 Jan 2004 04:16:12 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Dynamically resizing forms & controls

2. resizing a form when a control resizes during execution

3. Resize form - resize controls

4. Correction: Resize form - resize controls

5. Resizing a control when the Form is resized

6. resizing a form when a control resizes during execution

7. Resizing all controls at form resize

8. Moving user controls when a form is resized

9. Resize and move controls under the change of the Form size

10. Resize and move controls under the change of the Form size

11. How to automate moving controls when form resizes?

12. Resize, resize, resize, ...

 

 
Powered by phpBB® Forum Software