|
-
Nov 29th, 2001, 03:10 PM
#1
Thread Starter
New Member
Resolution Independent Forms
I am looking to display VB forms in a resolution independent environment.
I can't create an array of controls that can be resized at design time as each control must be individually named.
Is it possible to create a form that can be de displayed in all screen resolutions without having to code for the lowest common demoninator i.e. 640 * 480 display?
Can forms be displayed on a screen with scroll bars like occurs for web pages within an Internet browser, i.e. it doesn't matter about the resolution of the screens as all text within the browser can be seen with the help of scroll bars?
-
Nov 29th, 2001, 03:19 PM
#2
Frenzied Member
could you tell us the purpose of your app? maybe we could help you a bit more
I'm bringing geeky back...
-
Nov 29th, 2001, 03:19 PM
#3
Frenzied Member
resolution independent environment??
Do you mean the controls would size to the screen size???
I have a control that does it if you want.....
-
Nov 29th, 2001, 05:10 PM
#4
Hyperactive Member
' Taken from Microsoft Knowledgebase Article ID: Q182070
' 1) Change the video resolution to 800 x 600.
' 2) Start a new project in Visual Basic. Form1 is created by default.
' 3) Add a Label, a CommandButton, and any other types of controls you would like to test.
' Copy the following code into the Form's module:
[CODE]
Dim MyForm As FRMSIZE
Dim DesignX As Integer
Dim DesignY As Integer
Private Sub Form_Load()
Dim ScaleFactorX As Single, ScaleFactorY As Single ' Scaling factors
' Size of Form in Pixels at design resolution
DesignX = 800
DesignY = 600
RePosForm = True ' Flag for positioning Form
DoResize = False ' Flag for Resize Event
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips ' X Pixel Resolution
' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
ScaleMode = 1 ' twips
'Exit Sub ' uncomment to see how Form1 looks without resizing
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
" by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub
Private Sub Form_Resize()
Dim ScaleFactorX As Single, ScaleFactorY As Single
If Not DoResize Then ' To avoid infinite loop
DoResize = True
Exit Sub
End If
RePosForm = False
ScaleFactorX = Me.Width / MyForm.Width ' How much change?
ScaleFactorY = Me.Height / MyForm.Height
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub
Private Sub Command1_Click()
Dim ScaleFactorX As Single, ScaleFactorY As Single
DesignX = Xpixels
DesignY = Ypixels
RePosForm = True
DoResize = False
' Set up the screen values
Xtwips = Screen.TwipsPerPixelX
Ytwips = Screen.TwipsPerPixelY
Ypixels = Screen.Height / Ytwips ' Y Pixel Resolution
Xpixels = Screen.Width / Xtwips ' X Pixel Resolution
' Determine scaling factors
ScaleFactorX = (Xpixels / DesignX)
ScaleFactorY = (Ypixels / DesignY)
Resize_For_Resolution ScaleFactorX, ScaleFactorY, Me
Label1.Caption = "Current resolution is " & Str$(Xpixels) + _
" by " + Str$(Ypixels)
MyForm.Height = Me.Height ' Remember the current size
MyForm.Width = Me.Width
End Sub
' 4) Add a Module from the Project menu and paste in the following code:
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 RePosForm As Boolean
Public DoResize As Boolean
Sub Resize_For_Resolution(ByVal SFX As Single, _
ByVal SFY As Single, MyForm As Form)
Dim I As Integer
Dim SFFont As Single
SFFont = (SFX + SFY) / 2 ' average scale
' Size the Controls for the new resolution
On Error Resume Next ' for read-only or nonexistent properties
With MyForm
For I = 0 To .Count - 1
If TypeOf .Controls(I) Is ComboBox Then ' cannot change Height
.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
.Controls(I).FontSize = .Controls(I).FontSize * SFFont
Next I
If RePosForm Then
' Now size the Form
.Move .Left * SFX, .Top * SFY, .Width * SFX, .Height * SFY
End If
End With
End Sub
[CODE]
-
Nov 29th, 2001, 05:10 PM
#5
Use an MDI interface, make all your forms Child forms and you're done
To create one, click the Project Menu, select Add MDI form. Set all the MDIChile properties of each form to True and that's it...
-
Nov 29th, 2001, 05:27 PM
#6
-
Nov 29th, 2001, 07:22 PM
#7
PowerPoster
If you resize all the controls on the form at runtime, then it'll will be to resize according to the resolution unless you use - or + (eg A.Top = Me.ScaleHeight-3: this will move to control to 3 pixels less than the form's height no matter what the resolution is).
-
Nov 30th, 2001, 03:18 AM
#8
Originally posted by Mc Brain
That's not true. If you create an extremely big form, you won't see the whole form on a smaller resolution.
Okay, but you WILL see scrollbars and won't have to write ANY extra code for resizing:
Can forms be displayed on a screen with scroll bars like occurs for web pages within an Internet browser, i.e. it doesn't matter about the resolution of the screens as all text within the browser can be seen with the help of scroll bars?"
There you have it...
Originally posted by abdul
If you resize all the controls on the form at runtime, then it'll will be to resize according to the resolution unless you use - or + (eg A.Top = Me.ScaleHeight-3: this will move to control to 3 pixels less than the form's height no matter what the resolution is).
Just to remind ya'll: VB works with TWIPS as default, NOT pixels
-
Dec 12th, 2001, 11:00 AM
#9
New Member
I didn't notice that to be true either. You still don't see the entire form...
Are you frum?
http://www.FrumForum.com
-
Dec 12th, 2001, 11:19 AM
#10
PowerPoster
Originally posted by RobIII
Just to remind ya'll: VB works with TWIPS as default, NOT pixels
I was assuming you had set the screen mode to "Pixels". I always do that whenever I am performing this kind of operation.
-
Dec 12th, 2001, 11:47 AM
#11
New Member
Still doesn't do it... more details please...
Are you frum?
http://www.FrumForum.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|