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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control resizing 2

Status
Not open for further replies.

wallywojo

Programmer
Aug 30, 1999
36
US
I have an application that needs to tolerate changes in resolution. I have how to change the form, but need help with the sizing of controls. Any help would be apprecated.<br>
<br>
Walter Wojciechowski<br>
Wislon Pet Supply<br>
<A HREF="mailto:wwojo@wilsonpet.com">wwojo@wilsonpet.com</A><br>

 
You can check the height and width property of screen and then resize the form, Normally design for 640x480, but if user runs the application at 800x600 then following code might be of some help. <br>
<br>
Here the form is center located and made half, manipulate the code and check for yourself.<br>
<br>
Private Sub Form_load ()<br>
Width = Screen.Width * .75 ' Set width of form.<br>
Height = Screen.Height * .75 ' Set height of form.<br>
Left = (Screen.Width - Width) / 2 ' Center form horizontally.<br>
Top = (Screen.Height - Height) / 2 ' Center form vertically.<br>
End Sub<br>
<br>
If you are using VB6 then check the help for topic<br>
&quot;Designing for Different Display Types&quot;<br>
<br>
I hope its OK. <p>Manoj Kalekar<br><a href=mailto:manoj_kalekar@yahoo.com>manoj_kalekar@yahoo.com</a><br><a href= > </a><br>
 
A simpler approach might be to use a &quot;container control&quot;. This is something like a frame - but you can't see it. You Put this container control on your form - drop all your control's onto it and, when you run it, it copes with resize requests for you...<br>
<br>
I used to use one with VB3 called &quot;Elastic&quot; but I can't remember where is got it from or anything - been a while now.<br>
<br>
Have a poke around, shouldn't be too difficult to find.<br>
<br>
Oh - and let us know what you find and how well it worked etc.<br>
<br>
Regards<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Hi WallyW<br>
<br>
There are a few aspects how you can handle the problem :<br>
1. Check the resolution of the computer during runtime by calling the API and then move your controls around at runtime to accommodate that resolution. You may want to shift these controls to other positions or make them smaller or larger. When I do this I usually write for very high resolutions and then run my program for all the lower resolutions and have routines that shift and size these controls.<br>
2. There was a thread here about a month ago which had code for resizing the form and controls based on a scale factor and scaling the fonts as well. You can check that. I copied the code then and can give it to you if you do not find it here.<br>
<br>
<br>
PK <br>

 
I have not been able to find the container control. In the help index, it mentions ISimpleFrameSite, but this does not resize forms.
 
pk, can you send me that code? My email at work is:<br>
<br>
<br>
<A HREF="mailto:wwojo@wilsonpet.com">wwojo@wilsonpet.com</A><br>
Thanks,<br>
Wally Wojo<br>

 
Thanks Mike, that site is exactly what I needed. Appreciate the help.<br>
<br>
Wally Wojciechowski
 
Another thing to check in your form_resize event is the windowstate. If the form is minimized you want to return immediately, and not do anything. Otherwise you'll get errors because the controls you're attempting to move aren't visible. All it takes is this at the top of the event:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;If Me.WindowState = vbMinimized Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub '&lt;-------<br>
&nbsp;&nbsp;&nbsp;&nbsp;End If<br>
<br>
Chip H.<br>

 
Add a module.bas :<br>
<br>
'Resize routines<br>
'Eric De Decker<br>
'Secretaris VBG België<br>
' <A HREF="mailto:vbg.be@vbgroup.nl">vbg.be@vbgroup.nl</A><br>
<br>
Option Explicit<br>
Public Xtwips As Integer, Ytwips As Integer<br>
Public Xpixels As Integer, Ypixels As Integer<br>
<br>
Type FRMSIZE<br>
Height As Long<br>
Width As Long<br>
End Type<br>
<br>
Public Positie_Form As Boolean<br>
Public NuResize As Boolean<br>
Dim DesignX As Integer<br>
Dim DesignY As Integer<br>
Dim ScaleFactorX As Single, ScaleFactorY As Single<br>
Dim MyForm As FRMSIZE<br>
<br>
A routine (procedure to the module ) :<br>
<br>
Public Sub FormResize(TheForm As Form)<br>
Dim ScaleFactorX As Single, ScaleFactorY As Single<br>
If Not NuResize Then<br>
NuResize = True<br>
Exit Sub<br>
End If<br>
Positie_Form = False<br>
ScaleFactorX = TheForm.Width / MyForm.Width<br>
ScaleFactorY = TheForm.Height / MyForm.Height<br>
Resize_Resolutie ScaleFactorX, ScaleFactorY, TheForm<br>
MyForm.Height = TheForm.Height<br>
MyForm.Width = TheForm.Width<br>
End Sub<br>
<br>
a other procedure :<br>
<br>
Sub Resize_Resolutie(ByVal SFX As Single, ByVal SFY As Single, MyForm As Form)<br>
Dim I As Integer<br>
Dim SFFont As Single<br>
SFFont = (SFX + SFY) / 2<br>
On Error Resume Next<br>
With MyForm<br>
For I = 0 To .Count - 1<br>
If TypeOf .Controls(I) Is ComboBox Then<br>
.Controls(I).Left = .Controls(I).Left * SFX<br>
.Controls(I).Top = .Controls(I).Top * SFY<br>
.Controls(I).Width = .Controls(I).Width * SFX<br>
Else<br>
.Controls(I).Move .Controls(I).Left * SFX, _<br>
.Controls(I).Top * SFY, _<br>
.Controls(I).Width * SFX, _<br>
.Controls(I).Height * SFY<br>
<br>
End If<br>
If TypeOf .Controls(I) Is DBGrid Then<br>
<br>
Else<br>
<br>
.Controls(I).FontSize = .Controls(I).FontSize * SFFont<br>
End If<br>
Next I<br>
<br>
If Positie_Form Then<br>
<br>
.Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY<br>
<br>
End If<br>
End With<br>
<br>
<br>
End Sub<br>
<br>
Next procedure :<br>
<br>
Public Sub SizeForm(TheForm As Form)<br>
Dim Resolut As String<br>
DesignX = 1024<br>
DesignY = 768<br>
Positie_Form = True<br>
NuResize = False<br>
Xtwips = Screen.TwipsPerPixelX<br>
Ytwips = Screen.TwipsPerPixelY<br>
Ypixels = Screen.Height / Ytwips<br>
Xpixels = Screen.Width / Xtwips<br>
ScaleFactorX = (Xpixels / DesignX)<br>
ScaleFactorY = (Ypixels / DesignY)<br>
TheForm.ScaleMode = 1<br>
Resize_Resolutie ScaleFactorX, ScaleFactorY, TheForm<br>
Resolut = Str$(Xpixels) + &quot; by &quot; + Str$(Ypixels)<br>
MyForm.Height = TheForm.Height<br>
MyForm.Width = TheForm.Width<br>
<br>
End Sub<br>
<br>
The Form :<br>
<br>
Private Sub Form_Load()<br>
Call SizeForm(Me)<br>
End Sub<br>
<br>
Private Sub Form_Resize()<br>
<br>
Call FormResize(Me)<br>
<br>
End Sub<br>
<br>
From Eric De Decker<br>
<br>
<A HREF="mailto:vbg.be@vbgroup.nl">vbg.be@vbgroup.nl</A><br>
<br>

 
Eric,<br>
<br>
Thanks - nice code there.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top