CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Resolution

  1. #1
    Join Date
    Jul 1999
    Posts
    84

    Resolution

    Hello,

    How can we make an application Resolution independent and font independent?


    Thanks
    Harini

  2. #2
    Join Date
    Jan 2001
    Posts
    165

    Re: Resolution

    You'll need to scale all your components using the screen.width and screen.height properties.

    Form1.width = screen.width
    Form1.height = screen.height

    I haven't done a lot with scaleing an app but you would probably want to set up a scaleing based on the screen.width and screen.height properties. For example if you design your app to run best at 800x600 then you would probably do something like this:

    Form1.width = ((screen.width/screen.twipsperpixelx) / 800) * Form1.width

    Form1.height = ((screen.height/screen.twipsperpixely) / 600) * Form1.height

    In this manner you are scaleling whatever you designed by the current resolution to maintain proportion.

    You would also need to adjust left and top properties I would imagine in a similar fashion.

    -K


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Resolution

    The following is a simple code that you can use to make a form designed in 800x600 mode uniform over all resolutions.


    private Sub Form_Load()
    on error resume next
    Dim CtrlVar as Control
    Xratio = Screen.Width / (Screen.TwipsPerPixelX * 800)
    Yratio = Screen.Height / (Screen.TwipsPerPixelY * 600)
    for Each CtrlVar In FrmVar.Controls
    CtrlVar.Left = CtrlVar.Left * Xratio
    CtrlVar.Top = CtrlVar.Top * Yratio
    CtrlVar.Width = CtrlVar.Width * Xratio
    CtrlVar.Height = CtrlVar.Height * Yratio
    CtrlVar.Font.Size = CtrlVar.Font.Size * XRatio
    next CtrlVar
    End Sub





  4. #4
    Join Date
    Jul 1999
    Posts
    84

    Re: Resolution

    Hello Shree,

    Thanks for ur prompt reply.

    We have tried the method suggested by you. Somehow we still have problems. Could you please tell us where we are going wrong.
    I have one Main MDI form and four child forms.

    Here is the code that I Placed in the form_load.


    xratio = Screen.Width / (Screen.TwipsPerPixelX * 1024)
    yratio = Screen.Height / (Screen.TwipsPerPixelY * 768)
    me.Left = 3766 * xratio
    me.Top = 1130 * yratio
    me.Width = 6250 * xratio
    me.Height = 3800 * yratio




    With the above code the form appears on the main MAin MDI form at the required position with required size. However if I change the resolution to 800 x 600 then the form size gets distrubed. Am I doing some thing wrong.


    Please suggest accordingly

    Thanks
    Harini

  5. #5
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Resolution

    If you step through your code, you might see that Screen.Width is not being returned correctly. I don't think that this problem will persist in the executable. You'll see that the program performs as expected if you quit and restart VB after changing the screen resolution. Not all programs perform predictably after changing the display properties.



  6. #6
    Join Date
    Jul 1999
    Posts
    84

    Re: Resolution

    Hello Shree,

    The advice that you gave is really working out well.
    Now that the form and the controls are resized as per the systems resolution, the following are the problems that I am facing now.

    1. When I debug the code, it shows that the frames in form are moved, by changin the left, top, height and width. But this is not shown when the application is run.
    2. The font size is not changed even in the debug mode, nor is it shown when the application is run.

    Please help me out with the above two issues.


    Thanks
    Harini

  7. #7
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Resolution

    1. I'm not sure
    2. You must be using the MS Sans Serif font (the default) and it is not a truetype font, so it cannot have a size less than 8. Use some other font, such as Arial.


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

Featured