automatically resize controls - code snippet 
Author Message
 automatically resize controls - code snippet

Hi,

an often asked question is
*how to correctly resize controls in the form_resize() event*

Here's a code snippet that works for me (VB5). It resizes any control in the
form
automatically with the right proportions (do you say *proportions* in
english?) exept (I still wonder why) controls in the ssTab-container.

Remove the semicolons when pasting, they only indicate the end of larger
codelines

Private Sub Form_Resize()

'If there are no changes exit sub
If Me.Width = form_width And Me.Height = form_height Then Exit Sub

'If the form is only minimized exit sub
If Me.WindowState = vbMinimized Then Exit Sub

'Size of changes?
form_widthmove = Me.Width - form_width
form_heightmove = Me.Height - form_height

'Factor of changes?
form_widthmove_factor = form_widthmove / form_width
form_heightmove_factor = form_heightmove / form_height

'looping through all controls
control_number = Me.Count

For i = 0 To control_number - 1

'Message for debugging
'MsgBox (Controls(i).Name)

'Some controls (like Commondialog) cant be resized
'so we got to have an error_handler
On Error Resume Next

new_control_width = Controls(i).Width + Controls(i).Width *
form_widthmove_factor;
new_control_height = Controls(i).Height + Controls(i).Height *
form_heightmove_factor;
new_control_left = Controls(i).Left + Controls(i).Left *
form_widthmove_factor;
new_control_top = Controls(i).Top + Controls(i).Top *
form_heightmove_factor;
Controls(i).Move new_control_left, new_control_top, new_control_width,
new_control_height;

Next i

'Remember new width and height
    form_width = Me.Width
    form_height = Me.Height

End Sub

Put these two lines in the Form_load() event:
form_width=me.width
form_height=me.height

Declare these varables as global in the general declarations:
dim form_width as single
dim form_height as single

Hope this helps. Of course it would be nice If anyone could enhance it to
work with the ssTab-Control.

Burkhard


(remove NOSPAM.)



Tue, 16 Jan 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Resizing controls automatically...

2. Resizing controls on forms automatically to suit screen resolutions

3. Resizing columns in datagrid control automatically

4. automatically resizing a control

5. Code Database Program - Store your code Snippets

6. Code Database Program- Store your code snippets

7. Windows forms designer automatically adds code that sets properties of custom controls

8. samples code snippets?

9. combobox: converting code snippet from VBA to VB

10. Code Snippet: Browse for Folder

11. Code snippet storage

12. Need code snippet for benchmarking a process.

 

 
Powered by phpBB® Forum Software