Click here to Skip to main content
13,258,269 members (39,809 online)
Rate this:
Please Sign up or sign in to vote.
Hi all

I m developing one windows application and i want it to run in any screen resolution.can u please tell me how to do that..

Thank you
Posted 13-Dec-12 21:17pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There is no "magic code" which makes it work. If you want to have a UI that re-sizes gracefully, then using winforms is a mistake - you need to look at WPF which is designed to do that kind of thing.

There is no automatic way to stretch things in Winforms - you can make the controls expand and contract by using the Anchor and Dock properties, but that does not change font sizes at all, so you can end up which huge buttons, with tiny text in the middle. You would have to handle the resize event, and change them all manually.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Here is a code block to do JUST what you want.

Its not my own code, although i did write something similar over 10 years ago.
This sample is from Planet Source Code

Every time i tried to paste the link it conked out for some mad reason.
So i have simply pasted the code below.

Option Explicit On
Public Class Form1
    Dim c(6, 0) As String
    Dim xx, yy As Long

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        xx = Me.ClientSize.Width
        yy = Me.ClientSize.Height
        taga(Me, xx, yy)
        'Me.WindowState = FormWindowState.Maximized 'Optional
    End Sub
    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Dim sX, sY As Double
        Dim j As Integer
        On Error Resume Next
        sX = Me.ClientSize.Width / xx
        sY = Me.ClientSize.Height / yy
        For j = 1 To c.GetUpperBound(1)
            mudar(Me, c(0, j), j, sX, sY)
        Next j
    End Sub
    Private Sub taga(ByVal ct As Object, ByVal w As Long, ByVal h As Long)
        Dim i, k As Integer
        Dim ctl As Control
        For Each ctl In ct.Controls
            If ctl.Name = "" Then Exit For
            k = c.GetUpperBound(1)
            ReDim Preserve c(6, k + 1)
            c(0, k + 1) = ctl.Name
            c(1, k + 1) = ctl.Left
            c(2, k + 1) = ctl.Top
            c(3, k + 1) = ctl.Width
            c(4, k + 1) = ctl.Height
            c(5, k + 1) = ctl.Font.Size
            c(6, k + 1) = ctl.Font.Style
            i = ctl.Controls.Count
            If i > 0 Then
                taga(ctl, ctl.Width, ctl.Height)
            End If
        Next ctl
    End Sub
    Private Sub mudar(ByVal cm As Object, ByVal s As String, ByVal n As Integer, ByVal x As Double, ByVal y As Double)
        Dim ct As Control
        For Each ct In cm.controls
            If ct.Name = s Then
                ct.Left = c(1, n) * x
                ct.Top = c(2, n) * y
                ct.Width = c(3, n) * x
                ct.Height = c(4, n) * y
                If x < y Then
                    ct.Font = New System.Drawing.Font(ct.Font.Name, c(5, n) * x)
                    ct.Font = New System.Drawing.Font(ct.Font.Name, c(5, n) * y)
                End If
                ct.Font = New System.Drawing.Font(ct.Font, c(6, n))
                Exit For
                mudar(ct, s, n, x, y)
            End If
    End Sub
End Class
Snehasish Nandy 26-Dec-12 5:17am
Please tell me to use this code what changes i have to make...
Zaf Khan 28-Dec-12 21:16pm
You shouldn't have to change anything.
Did you ACTUALLY Try the code???

Did you place many controls on a form and RESIZE the form by dragging the form BORDERS?

Did you CHANGE your SCREEN RESOLUTION and check the form again?

Maybe if you do those things then you will see it works okay it resizes ALL the controls proportionally.

You must LIMIT the MINIMUM size of the form allowable or text will become unreadable!

Thats not too difficult once you have your form controls laid out nicely where you want them.

Finally if your still stuck POST your Forms DESIGNER file which is usually named as follows and lives in the relevant project folder.


Zaf Khan 28-Dec-12 21:18pm
What resolution are you working with (natively)
and what resolutions do you expect to use your application in too?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100