Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Form_Resize() - Resizing all controls.


Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2002, 10:30 AM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Unhappy Form_Resize() - Resizing all controls.


I'm about to pull my hair out over here. My subs
and functions usually work perfectly and and look
beautiful as far as layout and indention and that
type of thing. But anyways, I'm making some code
for my Form_Resize() sub and I don't like it
because I'm just about hardcoding every value into
it. I mean, look at this ugly code...
Code:
Private Sub Form_Resize()
        
        ' The tabbed menu...
        With tabMenu
        
            .Width = Me.Width - 170
            
                ' If the height of this form is
                ' greater than 900 than continue...
                If (Me.Height >= 900) Then
                
                    .Height = Me.Height - 1500
                    
                End If
                
                
            lstviewFiles.Width = .Width - 2000
            lstviewFiles.Height = .Height - 2000
            
            lstWindows.Width = .Width - 2000
            lstWindows.Height = .Height - 1200
            
        End With
        
        If (tabMenu.TabCaption(tabMenu.Tab) = "Windows") Then
    
            Dim intcmdWindows As Integer
        
                ' Loop through our cmdWindows array...
                For intcmdWindows = cmdWindows.LBound To cmdWindows.UBound
                
                    cmdWindows(intcmdWindows).Left = lstWindows.Width + 600
                    
                Next intcmdWindows
            
            lnHoriz1.X1 = cmdWindows(1).Left
            lnHoriz1.X2 = lnHoriz1.X1 + cmdWindows(1).Width
            
        End If
    
End Sub
It works fine, then next thing I know it
fails on me. The controls maybe would be a little shorter
or longer in height or width or something like that. I
need improvement type help on this. I mean, I think
I should use me.ScaleHeight instead of using me.Height. Maybe
I should use me.scaleWidth instead of me.Width.
Anyways, I just can't stand to look at it no longer.
Please help if you can.
Reply With Quote
  #2  
Old 04-28-2002, 02:32 PM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Talking

I just wanted to say this problem was resolved by yours truly.

Edit: NEVERMIND: The controls still come up short?

Last edited by Agent; 04-28-2002 at 02:58 PM.
Reply With Quote
  #3  
Old 04-28-2002, 05:56 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Can you tell us what you tried, and if it fixed any part of your problem?

Let me give you my advice:
The code is really not that bad "looking", but there are a couple of improvemnts you could make to the functionality which may help with your problem.

The reason your controls are no longer the correct size is that you are explicitly changing their size (to a set size) in your code.

Yes you should be using the ScaleHeight and ScaleWidth properties of the form.

You do have the right idea about only changing the controls when the size of the form reaches a certain criteriea but I hope the 900 is in twips, not pixels.

I am attaching a project I just wrote specificly for this post, have a look and see if it helps you out, take special notice of the positioning of the text boxes in design view. I feel that if you are using the Resize event for adjusting controls then there is no need to line them up at all in design view.

HTH,
Orbity
Attached Files
File Type: zip resizing.zip (1.6 KB, 42 views)
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy

Last edited by Orbity; 04-28-2002 at 06:10 PM.
Reply With Quote
  #4  
Old 04-28-2002, 07:18 PM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default

Quote:
The reason your controls are no longer the correct size is that you are explicitly changing their size (to a set size) in your code.
Well, you made a good example and thanks for it but see... I want/need to subtract maybe 300 pixels from the width, or something like that.

The truth is I really need to learn about scaleheight and scalewidth, pixels, twips and whatever about screen/form properties.

Thanks alot.


Anybody know any good tutorials about that???
Reply With Quote
  #5  
Old 04-28-2002, 07:40 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

It is really pretty straight forwrad:

Me.ScaleLeft 'Left of the client area
Me.ScaleTop 'Top of the client area
Me.ScaleWidth 'Width of the client area
Me.ScaleHeight 'Height of the client area

Screen.TwipsPerPixelX 'How many twips per pixel horizontally
Screen.TwipsPerPixelY 'How many twips per pixel vertically

This is how to find the number of pixels wide and tall your form's client area is when the form's scale mode is set to pixels:
Code:
Debug.Print Me.ScaleWidth / Screen.TwipsPerPixelX
Debug.Print Me.ScaleHeight / Screen.TwipsPerPixelY
Did this clear anything up, if not what is still confusing you?

Orbity
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #6  
Old 04-28-2002, 08:02 PM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default

Great! But I do have some questions about some definitions...
  • Client area
    This may sound dumb but do you mean the form area? or do you mean the Client's (the user's) area of their screen?
  • Twip
    What in the world?
I guess when I learn what a Twip is, I could understand...
Quote:
Screen.TwipsPerPixelX 'How many twips per pixel horizontally
Screen.TwipsPerPixelY 'How many twips per pixel vertically
Also, what should I have my form's scale mode set to? I have it (default) on twips right now.

Thanks for clearing things up!
Reply With Quote
  #7  
Old 04-29-2002, 06:43 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Quote:
Client area
This may sound dumb but do you mean the form area? or do you mean the Client's (the user's) area of their screen?
This is the area in which you place all your controls. This does NOT include the titlebar, menus, or borders of the form.

Quote:
Twip
What in the world?
Quote:
From MSDN:
Twip
A screen-independent unit used to ensure that placement and proportion of screen elements in your screen application are the same on all display systems. A twip is a unit of screen measurement equal to 1/20 of a printer's point. There are approximately 1440 twips to a logical inch or 567 twips to a logical centimeter (the length of a screen item measuring one inch or one centimeter when printed).
It is simply a different unit of measurement similar to pixel, centimeter, inch, ect...

HTH,
Orbity
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #8  
Old 05-01-2002, 01:22 PM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default

Thanks a whole lot, Orbitiy.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->