|
-
making form compatible with all screen resolutions
I ve been breaking head for this trouble for a week. I used 2 type of methods to adjust screen resolution :
I designed my form in 800*600 resolution and has given form.windowstate =2 for displaying full form. I ve viewing this form in other resolutions please help me.
1) This I put up in module and called it in form_Resize and form_load:
Dim ctl As Control
For Each ctl In Me.Controls
ctl.Height = ctl.Height * 100 / 78.125 ' (1024:100 = 800:x)
ctl.Width = ctl.Width * 100 / 78.125 ' (768:100 = 600:x)
Next ctl
Me.Height = Me.Height * 100 / 78.125
Me.Width = Me.Width * 100 / 78.125
End Sub
Above code gives error at the point ctl.height .Run time error: 438 Object does not support this property or method. I Can't figure out how to
straighten out this.
I tried this api method too:
Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Declare Function EnumDisplaySettings Lib "user32.dll" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lpDevMode As Any) As Boolean
Public Declare Function ChangeDisplaySettings Lib "user32.dll" Alias "ChangeDisplaySettingsA" (lpDevMode As Any, ByVal dwFlags As Long) As Long
Dim a As Boolean
Dim i&
i = 0
Do
a = EnumDisplaySettings(0&, i&, DevChg)
i = i + 1
Loop Until (a = False)
Dim b&
DevChg.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevChg.dmPelsWidth = iWidth
DevChg.dmPelsHeight = iHeight
b = ChangeDisplaySettings(DevChg, 0)
where iwidth and iHeight are:800 and 600 respectively in which I designed my forms.
Running from 640*480 display, though resolution becomes 800*600, the place where taskbar appears becomes hollow and displays green of desktop. At the same time
taskbar appears 1.5 inches above its original place, hiding some buttons in the application, with its length shortened by 2 inches.
Running from 1024*768 resolution, display becomes 800*600, the place where taskbar appears becomes hollow and displays green of desktop. The tagline of icons in the last row
become a bit hidden, and task bar completely hidden(I suppose it goes below the screen). I could only access every application using Alt+tab shortcut. Apart from this trouble, whatever
vbmodal form I display, becomes left aligned despite giving the line of code:
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
Later I found out the screen.width here becomes 12000 rather than 9000 which is in original 800*600 execution of program.
I slightly changed the code to work for all kinds of resolution and also while exiting the application, the original resolution to be restored. That's working fine.
I require that, taskbar must come in its original space irrespective of the resolution from which program runs, not disturbing the alignment of vbmodal forms I display. How to modify the code
with API please anybody let me know?
If there are other better ways too let me know.
THis I used finally but this too is giving me lot of headache.
'This is in module
Public Xtwips As Integer, Ytwips As Integer
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
Dim MyForm As FRMSIZE
Dim DesignX As Integer
Dim DesignY As Integer
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
' Be sure to resize and reposition before changing the FontSize
.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
'This is in form_load event, also form_resize event.
Sub get_form_screen_parameters(frm As Form)
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, frm
'Label1.Caption = "Current resolution is " & str$(Xpixels) + _
' " by " + str$(Ypixels)
MyForm.Height = frm.Height ' Remember the current size
MyForm.Width = frm.Width
End Sub
I slightly changed the variation of this code for 1st method such that it scales things. But still the performance is unsatisfactory. If I minimize the form, every character becomes more than 500 font size. Not only that during normal execution, though 1/3rd part of a form which is unused in 1024*768 disappears, form becomes big and I could not view many controls in its maximized size. I think many things go off screen.
Similar Threads
-
Replies: 1
Last Post: 06-14-2002, 03:49 PM
-
By Al Guten in forum .NET
Replies: 0
Last Post: 04-11-2002, 06:48 PM
-
By James Brown in forum VB Classic
Replies: 3
Last Post: 03-26-2002, 09:35 AM
-
By Jim Burak in forum Architecture and Design
Replies: 1
Last Post: 07-20-2001, 12:43 PM
-
By Setya in forum VB Classic
Replies: 0
Last Post: 01-08-2001, 05:53 AM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks