Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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.
 
Share this answer
 
 
Share this answer
 
v2
Here is a code block to do JUST what you want.

NOTE:
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.

VB
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)
                Else
                    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
            Else
                mudar(ct, s, n, x, y)
            End If
        Next
    End Sub

End Class
 
Share this answer
 
Comments
[no name] 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.

Obviously THERE IS A DRAWBACK!!
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.

FORMNAME.designer.vb

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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900