Results 1 to 17 of 17

Thread: change resoulations back and forth

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    change resoulations back and forth

    Hi wireguys
    Been fighting screen resoulations . My setup now checks the screen res and adjusts the form accordingly for each res. Never had got this to perfection. My form on a pc running 1600x1200 my form is tiny and it is way too big too fit on 680x400. I do not like changing a users resolutation.Has anyone tried this:
    Detect and change a users resolutation on form load and change it back if they click out of my program.and change it back when my program gets the focus again. I kinda got started and found i could not detect when a user clicks out of my form. The form lost focus seems worthless. How could i detect this?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: change resoulations back and forth

    There is no way to do that reliably - even if your code is really good, there is always the chance that your program will be too busy, or perhaps even crash (thus leaving the user in the wrong resolution).

    There are also other reasons you should not do it, such as a change of resolution moves icons that are on the desktop.


    Why don't you do what other programs do instead - and get your resize code working properly? If you need help with it, we're here.

  3. #3
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: change resoulations back and forth

    Personally I would get very annoyed with any desktop software that changed my screen resolution. However, even my Dad (60) has moved on from 680x400, and my graphics cards minimum is 800x600.

    Hands up anyone who knows someone still working with 600x480?

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: change resoulations back and forth

    Quote Originally Posted by si_the_geek
    There is no way to do that reliably - even if your code is really good, there is always the chance that your program will be too busy, or perhaps even crash (thus leaving the user in the wrong resolution).

    There are also other reasons you should not do it, such as a change of resolution moves icons that are on the desktop.


    Why don't you do what other programs do instead - and get your resize code working properly? If you need help with it, we're here.
    I am worn out on resizing even purchased activeresize from vbgold. never can get the text to look properly.

  5. #5

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: change resoulations back and forth

    Quote Originally Posted by isnoend07
    I am worn out on resizing even purchased activeresize from vbgold. never can get the text to look properly.
    And yes i use true type fonts

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: change resoulations back and forth

    Like many people here, I do it purely in code that I wrote myself... if you show us your code that does it (and give us an example of the problem(s)), we can help you correct it.

  7. #7

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: change resoulations back and forth

    Quote Originally Posted by si_the_geek
    Like many people here, I do it purely in code that I wrote myself... if you show us your code that does it (and give us an example of the problem(s)), we can help you correct it.
    Take a look here and let me know what you think
    http://roofgenius.com/Help/index.html

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: change resoulations back and forth

    Is that your program?

    If so, what do you think is wrong with the way it is displayed?

    Just as importantly, what is your resize code?

  9. #9
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: change resoulations back and forth

    Lately I've been working on how to handle scaling a form to match a screen resolution. While my solution doesn't yet handle advanced issues like tab controls, it works pretty darn nicely. It's even set up to automatically support regular or large fonts. All font sizes are based on screen resolution, and then the form and all controls are based on the font size.
    Code:
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long
    
    Public Sub FormLayout(pfrm As Form, pblnLargeFonts)
        Const SampleText = "Q"
        Dim sngFontSize As Single
        Dim lngWidth As Long
        Dim lngHeight As Long
        Dim lngExtraWidth As Long
        Dim lngExtraHeight As Long
        Dim sngX As Single
        Dim sngY As Single
        Dim ctl As Control
        
        LockWindow pfrm.hwnd
        sngFontSize = GetFontSize(pblnLargeFonts)
        If sngFontSize <> pfrm.FontSize Then
            With pfrm
                lngWidth = .TextWidth(SampleText)
                lngHeight = .TextHeight(SampleText)
                lngExtraWidth = .Width - .ScaleWidth
                lngExtraHeight = .Height - .ScaleHeight
                .FontSize = sngFontSize
                .Refresh
                sngX = .TextWidth(SampleText) / lngWidth
                sngY = .TextHeight(SampleText) / lngHeight
                .Move .Left, .Top, .ScaleWidth * sngX + lngExtraWidth, .ScaleHeight * sngY + lngExtraHeight
            End With
            On Error Resume Next
            For Each ctl In pfrm.Controls
                With ctl
                    If TypeOf ctl Is Line Then
                        .X1 = .X1 * sngX
                        .X2 = .X2 * sngX
                        .Y1 = .Y1 * sngY
                        .Y2 = .Y2 * sngY
                    Else
                        .FontSize = sngFontSize
                        .Move .Left * sngX, .Top * sngY, .Width * sngX, .Height * sngY
                    End If
                End With
            Next
            On Error GoTo 0
            Set ctl = Nothing
        End If
        UnlockWindow
    End Sub
    
    Public Function GetFontSize(Optional pblnLarge As Boolean = False) As Single
        Dim lngHeight As Long
        
        With Screen
            lngHeight = .Height \ .TwipsPerPixelY
        End With
        If pblnLarge Then
            GetFontSize = lngHeight \ 66
        Else
            Select Case lngHeight
                Case 1024: GetFontSize = 12
                Case Else: GetFontSize = lngHeight \ 75
            End Select
        End If
    End Function
    You may notice at the end there that I hardcode font size 12 for the standard 1280x1024 fonts. (The auto-calculated size would be 12.75 IIRC.)

    If you use this (or a modified version thereof) and decide that a hardcoded font size is appropriate for 1600x1200, please post here to let me know so I can include it. I can't run resolutions higher than 1280x1024, so I just have to hope they look okay.

    Usage would be to maintain a global setting for whether the user wants large fonts or not, and in each Form_Load event simply call:

    FormLayout Me, gblnLargeFonts

    And then I'd recommend adding a Large Fonts? checkbox under Tools => Options, and if they change it iterate through the Forms collection calling FormLayout:
    Code:
    For Each frm In Forms
        FormLayout frm, gblnLargeFonts
    Next

  10. #10
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: change resoulations back and forth

    A useful tip is to then design all your forms using at least 12 pt fonts. The reason is that if you set them up with smaller fonts, the gap between controls will grow along with the rest of the form and look too spaced out. But if you use the larger fonts to begin with, shrinking the gaps looks just fine.

    In my exhaustive testing, setting up a form in design view with 12pt fonts (I use Verdana) will result in very nice looking forms for both large and regular fonts in 800x600, 1024x762, 1152x864 and 1280x1024. I'm hoping it works equally well for 1600x1200; I'd really appreciate it if you gave it a try and let me know.

    NOTE: At design time, the form itself must be set to the same font / font size as the controls on it.

  11. #11

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: change resoulations back and forth

    Quote Originally Posted by si_the_geek
    Is that your program?

    If so, what do you think is wrong with the way it is displayed?

    Just as importantly, what is your resize code?
    The way it is displayed problem is it is real small in 1600x1200.

    Select Case res

    Case "640x480"
    MsgBox "RoofCalculator requires a minimum screen resolution of 800x600, best at 1280x1024"
    Unload Me

    Case "800x600"
    Me.Top = 0
    Me.Left = 0
    Me.Width = 12000
    Me.Height = 8600

    Case "1024x768"
    Me.Width = 12050
    Me.Height = 9000
    Me.Left = (Screen.Width - Me.Width) / 2
    Me.Top = (Screen.Height - Me.Height) / 2


    Case "1152x864" 'couldn't test this don't have this resolutation
    Me.Width = Screen.Width * 0.67
    Me.Height = 8840
    Left = (Screen.Width - Width) / 2
    Me.Top = (Screen.Height - Me.Height) / 2
    Me.Picture7.Width = Me.Width
    Me.picMain.Width = Me.Width
    I have tons of code for printing this form and have really had to make things a little smaller than i would have liked so all my grids lineup side by side and be able to print the form on 1 sheet of paper. It starts by having the pic holding customer address move to the top and hide the toolbar. Then hides a lot of things and puts everything back after printing.
    So i cannot make the form and controls bigger as they will not print correctly.
    i wish i could do this when printing if form is too large:
    Make all my print adjustments eg: this visible, that invisible grid1.left = 50
    grid2 left = grid1.left, grid2.top = grid1.top+grid1.height +50 etc
    Shrink everything print and put everything back and then unshrink everythin back to normal

  12. #12
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: change resoulations back and forth

    Maybe you could create a second version of the form that is printer only. Then when they print the form, print the (hidden?) printer-friendly version.

    Apart from the printing issue, I found that resizing based on the screen resolution produces suboptimal results. I was much happier with the results of identifying a font size based on the resolution, and then resizing based on the font size. I'm guessing this would also help deal with fixed-size controls like comboboxes.

  13. #13
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: change resoulations back and forth

    Though in looking at your link, I dunno. That's a whole lotta stuff to try and auto-resize.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: change resoulations back and forth

    ...or perhaps rather than using PrintForm, do the printing yourself (as many of us do). This doesn't need huge amounts of code, as you can use the .Picture property of the controls to print them (you just need to set the positions appropriately).

    Doing the printing yourself means that you can adjust the printout to the size of the paper (if you want to), and that your form does not need to be a fixed size (with Printform, your form needs to always stay the same size to print out the same).


    As for the resizing, I would recommend either code like Ellis posted (as it should also work for resolutions you haven't written specific code for), or use the _Resize event to resize/move each of the controls depending on the form size.

  15. #15

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: change resoulations back and forth

    Quote Originally Posted by Ellis Dee
    Lately I've been working on how to handle scaling a form to match a screen resolution. While my solution doesn't yet handle advanced issues like tab controls, it works pretty darn nicely. It's even set up to automatically support regular or large fonts. All font sizes are based on screen resolution, and then the form and all controls are based on the font size.
    Code:
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long
    
    Public Sub FormLayout(pfrm As Form, pblnLargeFonts)
        Const SampleText = "Q"
        Dim sngFontSize As Single
        Dim lngWidth As Long
        Dim lngHeight As Long
        Dim lngExtraWidth As Long
        Dim lngExtraHeight As Long
        Dim sngX As Single
        Dim sngY As Single
        Dim ctl As Control
        
        LockWindow pfrm.hwnd
        sngFontSize = GetFontSize(pblnLargeFonts)
        If sngFontSize <> pfrm.FontSize Then
            With pfrm
                lngWidth = .TextWidth(SampleText)
                lngHeight = .TextHeight(SampleText)
                lngExtraWidth = .Width - .ScaleWidth
                lngExtraHeight = .Height - .ScaleHeight
                .FontSize = sngFontSize
                .Refresh
                sngX = .TextWidth(SampleText) / lngWidth
                sngY = .TextHeight(SampleText) / lngHeight
                .Move .Left, .Top, .ScaleWidth * sngX + lngExtraWidth, .ScaleHeight * sngY + lngExtraHeight
            End With
            On Error Resume Next
            For Each ctl In pfrm.Controls
                With ctl
                    If TypeOf ctl Is Line Then
                        .X1 = .X1 * sngX
                        .X2 = .X2 * sngX
                        .Y1 = .Y1 * sngY
                        .Y2 = .Y2 * sngY
                    Else
                        .FontSize = sngFontSize
                        .Move .Left * sngX, .Top * sngY, .Width * sngX, .Height * sngY
                    End If
                End With
            Next
            On Error GoTo 0
            Set ctl = Nothing
        End If
        UnlockWindow
    End Sub
    
    Public Function GetFontSize(Optional pblnLarge As Boolean = False) As Single
        Dim lngHeight As Long
        
        With Screen
            lngHeight = .Height \ .TwipsPerPixelY
        End With
        If pblnLarge Then
            GetFontSize = lngHeight \ 66
        Else
            Select Case lngHeight
                Case 1024: GetFontSize = 12
                Case Else: GetFontSize = lngHeight \ 75
            End Select
        End If
    End Function
    You may notice at the end there that I hardcode font size 12 for the standard 1280x1024 fonts. (The auto-calculated size would be 12.75 IIRC.)

    If you use this (or a modified version thereof) and decide that a hardcoded font size is appropriate for 1600x1200, please post here to let me know so I can include it. I can't run resolutions higher than 1280x1024, so I just have to hope they look okay.

    Usage would be to maintain a global setting for whether the user wants large fonts or not, and in each Form_Load event simply call:

    FormLayout Me, gblnLargeFonts

    And then I'd recommend adding a Large Fonts? checkbox under Tools => Options, and if they change it iterate through the Forms collection calling FormLayout:
    Code:
    For Each frm In Forms
        FormLayout frm, gblnLargeFonts
    Next
    I have the same problem, didn't notice until a couple days ago my new monitor did not do 1600x1200 or 1152x864

    I like your code my project contains 21 forms, 20 i could use it on as they do not have to consider printing. The printing issue on my main form has kinda got my hands tied as far as rezing. Looks like i'm getting another new monitor

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: change resoulations back and forth

    Quote Originally Posted by isnoend07
    The printing issue on my main form has kinda got my hands tied as far as rezing.
    ..unless you write the printing code yourself.

    At a rough guess, it would be about 30 lines of code - and there is a tutorial in our Classic VB FAQ's that explains most of it (tho it may not mention using the .Picture property of controls).

  17. #17

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: change resoulations back and forth

    Quote Originally Posted by Ellis Dee
    Maybe you could create a second version of the form that is printer only. Then when they print the form, print the (hidden?) printer-friendly version.

    Apart from the printing issue, I found that resizing based on the screen resolution produces suboptimal results. I was much happier with the results of identifying a font size based on the resolution, and then resizing based on the font size. I'm guessing this would also help deal with fixed-size controls like comboboxes.
    I will give that some thought about a second hidden form.
    To look at the way my print looks now go here:
    http://roofgenius.com/print_roofcalculator.htm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width