Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Resizing

Status
Not open for further replies.

CenturioN101

Programmer
Jan 24, 2001
8
GB
Hi, I am doing a Computer Programming course and as a part of my course work I have been tasked in making a "User Friendly Application" (it can be whatever). But when the "User" resizes the windows everything stays in the same position as when I designed it in VB 6 (Duh). But I want it to keep objects like Command buttons at the bottom say 200px from the bottom and resize text boxes according to "User Preference". I know and am fully prepared for the FAT (meaning LARGE) wadd of coding that may be required for this.

Thnx in Advance and for your time
Brent

ps I already know the:

Form_Resize()
Text1.Move 200, 200, Me.Width - 200, Me. Height - 200
End
 
Ok, so you know how to move and resize the controls on the form. Was there a question in there somewhere? I didn't see one.

I'll give you some advice, though: If the user makes the form larger, resize the form first, and resize any containers before you resize the controls inside them. If the user makes the form smaller, resize the innermost controls first and work your way outward, resizing the form last.

Of course, the user could make the form both narrower and longer. In this case, you should change the lefts and widths from innermost to outermost, and change the tops and heights from outermost to innermost. Hey, nobody said it was easy, right?!

If you don't follow this advice, at some point you'll wind up trying to make a form too small to contain its controls, and it will refuse, leaving your form too tall/wide when you're done. Or, you'll try to make a control too big for its container, and the container will grow to accomodate it, so when you change the container later on, it winds up too big.

Even then, there are some special circumstances when you have to first make the width/height smaller, then change the left/top, then make the width/height bigger again to avoid this control/container interaction. Let's hope you won't run into those circumstances. Rick Sprague
 
I need code!!!!! cuz "what" I know is self taut that meens the teatcher refused to teach me VB. the actual assignment was to design a program, meaning web page with cgi bin and stuff like that, if we wanted to doo something different we had to research and teach ourselves how to do it, so here I am, trying to lern. But no offence (and thnx for your help) but to me what you said... it is useless, in time I may understand what your saying but right now (where it counts most) I have NO clue as to what your saying. I have no disk space for MSDN so that was ruled out! please can someone take time an give me code that says where i should put my object names in the code so I can lern off it. Please because I really try to help in the HTML and JS sections now I'm askin for other peoples help and nobody seem to know.

Thnx for your time Rick and others but I really do need code.

Brent Nebwury

PS. Please help, I help others in the HTML and JS sections in the past but, now I need other people help i don't get anything or I get a well, written bable to me (it may not seem bable to any1 else) PLease don't take offence Rick i don't meen to be an irrate customer but i don't understand.
 
'I give you a cursus Windows resize ;-)
' Add a Module to a project
' declarations :

Option Explicit
Public Xtwips As Integer, Ytwips As Integer
Public Xpixels As Integer, Ypixels As Integer

Type FRMSIZE
Height As Long
Width As Long
End Type

Public Positie_Form As Boolean
Public NuResize As Boolean
Dim DesignX As Integer
Dim DesignY As Integer
Dim ScaleFactorX As Single, ScaleFactorY As Single
Dim MyForm As FRMSIZE

'Copy next procedures in the module

Public Sub FormResize(TheForm As Form)
Dim ScaleFactorX As Single, ScaleFactorY As Single
If Not NuResize Then
NuResize = True
Exit Sub
End If
Positie_Form = False
ScaleFactorX = TheForm.Width / MyForm.Width
ScaleFactorY = TheForm.Height / MyForm.Height
Resize_Resolutie ScaleFactorX, ScaleFactorY, TheForm
MyForm.Height = TheForm.Height
MyForm.Width = TheForm.Width
End Sub

Sub Resize_Resolutie(ByVal SFX As Single, ByVal SFY As Single, MyForm As Form)
Dim I As Integer
Dim SFFont As Single
SFFont = (SFX + SFY) / 2
On Error Resume Next
With MyForm
For I = 0 To .Count - 1
If TypeOf .Controls(I) Is ComboBox Then
.Controls(I).Left = .Controls(I).Left * SFX
.Controls(I).Top = .Controls(I).Top * SFY
.Controls(I).Width = .Controls(I).Width * SFX
Else
.Controls(I).Move .Controls(I).Left * SFX, _
.Controls(I).Top * SFY, _
.Controls(I).Width * SFX, _
.Controls(I).Height * SFY

End If
If TypeOf .Controls(I) Is DBGrid Then

Else

.Controls(I).FontSize = .Controls(I).FontSize * SFFont
End If
Next I

If Positie_Form Then

.Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY

End If
End With


End Sub

Public Sub SizeForm(TheForm As Form)
Dim Resolut As String ' voor de resolutie waarde van het systeem
' gebruik de design resolutie van je system (800 - 600 )
DesignX = 1024
DesignY = 768
Positie_Form = True
NuResize = False
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips
Xpixels = Screen.Width / Xtwips
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
TheForm.ScaleMode = 1
Resize_Resolutie ScaleFactorX, ScaleFactorY, TheForm
Resolut = Str$(Xpixels) + " by " + Str$(Ypixels)
MyForm.Height = TheForm.Height
MyForm.Width = TheForm.Width

End Sub

'add next code to the form

Option Explicit

Private Sub Form_Load()
Call SizeForm(Me)
End Sub

Private Sub Form_Resize()

Call FormResize(Me)

End Sub

'Cheers Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Another tips for you Brent, ;-)

You can use F9 to put a break point while you program running.
ie you put the cursor on the line Private Sub Form_Load()
then press F9, VB will stop at that line, wait for your instruction.

You can use F8 to run your code line by line, step by step. This is very helpful to check if there's any error or bugs.

It is better if you test your program, you run it on 'Full Compile' mode (Ctrl + F5) coz VB will check code syntax and object properties.

Put an error trapping.

Private Sub Form_Load()
On Error GoTo ErrHandler
...'your code here
Exit Sub 'put exit sub so when everything goes fine, it won't go into the error trapping

ErrHandler: 'this is the error trap
MsgBox Err.Number & "-" & Err.Description, vbExclamation
Err.Clear
End Sub

:-D
 
Thnx m8 but, that code what I wound out only works for the top left and bottom right. NOT top right and bottom left. If someone could fiddle about with it to make it do that I would be very pleased.

And thnx again to Rick Eric and Shadow for your efforts.
It may look like i will have to resort to that long piece of code afterall Eric.

Thnx for your time lads
Brent Newbury aka "..CenturioN.."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top