[RESOLVED] Problem of screen resolution-VBForums
Results 1 to 18 of 18

Thread: [RESOLVED] Problem of screen resolution

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Resolved [RESOLVED] Problem of screen resolution

    hello everyone
    When I tested my application on my colleagues' computers I was surprised to see the size of the forms and controls are totally different from my mine.
    After some googling, I learnt that I have to design my application at a lower resolution. And this is what I did.
    I designed my new application at a resolution of 800 x 600
    Then I was faced with another prblem. when I switch at high resolution, there is too much empty space on the form which makes the application looks ugly.
    I managed to solve this problem partly because I found a free resizer ocx and it is working perfectly for form1.
    My main prblem now is form2. On this form there is a picture.
    I'm looking for a way to stretch the picture to fit the form or shrink (diminish) the form fit the picture (of course the high resolution is used).
    thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    16,536

    Re: Problem of screen resolution

    Stretch a picture? Use an image control and set the Stretch property to true. Resize the control as needed
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VB and DPI Tutorial} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    Quote Originally Posted by LaVolpe View Post
    Stretch a picture? Use an image control and set the Stretch property to true. Resize the control as needed
    Thank you for the quick reply but I have to use a picturebox and not a image control.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    Re: Problem of screen resolution

    You can use either StretchBlt or Picture1.PaintPicture to resize the picture but it wont resize the picturebox, just the picture in it. You;ll have to resize the picturebox by changing it's width and height to fit around the resized picture


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: Problem of screen resolution

    Here's a project that demonstrates several simple options for stretching pictures. The options includes the aforementioned Image control (top left image), the PaintPicture method (top right image) and the StretchBlt API function (bottom right image). Other choices presented in the demo are the Render method (bottom left image) and the StretchDIBits API function (same quadrant as StretchBlt). You'll probably find that the 2 API functions usually renders the best looking stretched images, thanks to SetStretchBltMode(..., STRETCH_HALFTONE).




    BTW, if you would like your picture to scale proportionally (i.e., preserve its aspect ratio), then you'll probably want to use this algorithm by LaVolpe.



    Last edited by Bonnie West; Nov 9th, 2015 at 02:29 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    Thank you all for your precious advice
    My picturebox contains an image on which there are some graphics based on some calculations. So I think I need to resize the form to fit the picture box instead of stretching the picture that may lead to lose my calculations.
    So let's imagine, my resolution is now 600x800, the form is fitting perfectly the picturebox. When I change the resolution to 1280x 768, I get so much empty space on the form.
    I wonder if there is a way to make the form look exactly as it is at the initial resolution(600x800). I want a code or a module to resize the form so as to get rid of that useless empty space when switching to a high resolution.

    Thank you for your advice
    Last edited by samer22; Oct 2nd, 2015 at 03:54 AM.

  7. #7
    Frenzied Member gibra's Avatar
    Join Date
    Oct 2009
    Location
    ITALY
    Posts
    1,397

    Re: Problem of screen resolution

    I think you intend 800x600 (not 600x800)...


    1. Take note that Screen object has a problem:

    PRB: Incorrect Screen Object Width/Height After the Desktop Is Resized
    https://support.microsoft.com/en-us/kb/253940


    2. When you changes the resolution (relationship between height and width), then if you want to keep the same proportion you have to choose which one you want to use mainly (height or width) because it is obvious that you can not have both.


  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    Thanks for the link
    Before I see the link I want explain further my need I want to know how to resize the form according to the screen resolution change .
    I did something like this and it seems to have some results.
    form2.Width = Picture1.Width * 400
    form2.Height = Picture1.Height * 400
    but it is not giving good results with all resolutions
    thank you

  9. #9
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Problem of screen resolution

    You have two problems here.

    One is resizing images... others have given you clues and examples on how to do this.

    But your main problem is that your forms, designed on a small screen resolution don't look good on higher resolution screens.

    There are ways around that. The trick is to size your controls in Percentage of screen resolution instead of fixed numbers in twips. It's quite easy to do. A little while back, I posted an example which did just that : it resizes all the controls on a form (including font size) when you resize the form, so no matter what the screen resolution is, the form looks always proportionally the same.

    The code is here, somewhere, in a thread. I'll try to find it for you and bring the piece of code in this thread. It's a good basic code sample, easy to understand yet very flexible. Just what you need IMO, for starters anyway.

  10. #10
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Problem of screen resolution

    Allright, here it is . Easier to find than I thought. Its a very basic piece of code, much to do to make it more flexible. It resizes controls, not images contained in them, like picture boxes. That is a different task, as discussed above.

    Among the improvements that can/need to be made :

    a) support for more control specific issues (if desired)
    b) put the code from the form into a module so you don't have to write it every time you create a new form.

    The original thread is here :

    RESOLVED-Back-to-Basics-Resizing-Shapes-and-Images

    more material to read on the subject.

    Code:
    Dim frmWidth
    Dim frmHeight
    
    Private Sub Form_Load()
    
    frmWidth = Me.ScaleWidth
    frmHeight = Me.ScaleHeight
    
    For Each ctrl In Me
        ctrl.Tag = ctrl.Left & "," & ctrl.Top & "," & ctrl.Width & "," & ctrl.Height & "," & ctrl.FontSize
        ctrl.Font = "Tahoma"
    Next
    
    End Sub
    
    Private Sub Form_Resize()
    If Me.WindowState = vbMinimized Then Exit Sub
    
    ratiox = Me.ScaleWidth / frmWidth
    ratioy = Me.ScaleHeight / frmHeight
    For Each ctrl In Me
        If Len(ctrl.Tag) Then
            arg = Split(ctrl.Tag, ",")
            ctrl.Move arg(0) * ratiox, arg(1) * ratioy, arg(2) * ratiox, arg(3) * ratioy
            ctrl.FontSize = arg(4) * IIf(ratiox < ratioy, ratiox, ratioy)
        End If
    Next
    
    End Sub

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    Thank you Navion for the help you are offering.
    I tried your code and Im having an error here.
    Code:
    ctrl.Tag = ctrl.Left & "," & ctrl.Top & "," & ctrl.Width & "," & ctrl.Height & "," & c
    the message says: object doesn't support this property or method

  12. #12
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Problem of screen resolution

    As I said, it is a very basic piece of code. It has been tested with a few of the more commonly used controls such as commandbutton, textbox, label, etc. Lots of things can happen.

    It is your job, as a programmer to learn how to handle specifics problems or issues that may happen.

    The code has to be augmented, according to the controls you are using. Not all the controls supports all the same properties and methods.

    Issues like you are having can be resolved with something like :

    Code:
    If TypeOf ctrl Is PictureBox Then
        'do this
        'don't do that
    ElseIf TypeOf ctrl Is Label Then
        'do this
        'don't do that
    Else
        'generic case...
        'no problem here
        'until one shows up
    End If

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,144

    Re: Problem of screen resolution

    If you found something online that advised you to develop at 800x600 it must have been pretty old. That res has not been the target since we moved from 14" CRTs and Windows 95. Most PCs now will run at minimum 1024x768 and the more common res will be wide screen HD 1920x1024.

    I generally try to keep my forms to where they can be used even at 800x600 but I develop on a machine that is running 1920x1024

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    Navion
    yes it seems that lines do not support that property

  15. #15
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    557

    Re: Problem of screen resolution

    Put this line in the loop, before the offending call, to find which control has a problem.

    Code:
    'either :
    
    debug.print ctrl.Name
    
    'or
    
    msgbox ctrl.Name

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    I need to know if it is possible to tell vb6 that
    If screen resolution is : 1024 x768 then form.width is.....
    elseif screen resolution is : 1280x600 then form.width is.....
    Is this possible ?
    Thanks for replying

  17. #17
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,072

    Re: Problem of screen resolution

    Use

    Screen.Width / Screen.TwipsPerPixelX
    Screen.Height / Screen.TwipsPerPixelY

    PHP Code:
    If Screen.Width Screen.TwipsPerPixelX 1024 And Screen.Height Screen.TwipsPerPixelY 768 Then
      Form
    .Width wwww
      Form
    .Height hhhh
    ElseIf Screen.Width Screen.TwipsPerPixelX 1280 And Screen.Height Screen.TwipsPerPixelY 600 Then
      Form
    .Width wwww
      Form
    .Height hhhh
    End 
    If 


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    489

    Re: Problem of screen resolution

    Quote Originally Posted by jmsrickland View Post
    Use

    Screen.Width / Screen.TwipsPerPixelX
    Screen.Height / Screen.TwipsPerPixelY

    PHP Code:
    If Screen.Width Screen.TwipsPerPixelX 1024 And Screen.Height Screen.TwipsPerPixelY 768 Then
      Form
    .Width wwww
      Form
    .Height hhhh
    ElseIf Screen.Width Screen.TwipsPerPixelX 1280 And Screen.Height Screen.TwipsPerPixelY 600 Then
      Form
    .Width wwww
      Form
    .Height hhhh
    End 
    If 
    Thank you very much great man
    it worked

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.