Hi,
I wantd to know how to adjust my form size such that, when i run my code in a different monitor with different screen resoultions my program should not look small or large.

Please help me with code for the same.
thanks
akhila

You might want to look at developing your application as a WPF application instead of Windows Forms. I understand it was designed to maintain consistency across multiple resolutions.

Develop your application by using WPF (Windows Presentation Foundation).
Start vb.net -> New Project ->WPF Application.

This how you get the screen resolution:

 Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
 Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height
 Label1.Text = (intX & " × " & intY)

and here isa little program that lets you play around with different screen sizes:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ScreenResolution()
        Me.Text = "Screen Size Display"
        Label5.Text = "ChildForm width=" & "  " & Form2.Width
        Label6.Text = "ChildForm width=" & "  " & Form2.Height
        Label7.Text = "ChildForm Top" & "  " & Form2.Top - Me.Top
        Label8.Text = "Childform Left" & "  " & Form2.Left - Me.Left
        TextBox1.Text = "600"
        TextBox2.Text = "800"
        GetVersionFromEnvironment()
    End Sub
    Public Sub ScreenResolution()
        Dim intX As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim intY As Integer = Screen.PrimaryScreen.Bounds.Height
        Me.Width = intX
        Me.Height = intY
        Label1.Text = (intX & " × " & intY)
        Form2.Show()
    End Sub
    Private Sub Go_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.WindowState = FormWindowState.Normal
        Dim scWidth As Long
        Dim scHeight As Long
        scWidth = CInt(TextBox1.Text)
        scHeight = CInt(TextBox2.Text)
        'Make sure the size is acceaptable
        If scHeight >= 200 And scWidth >= 200 Then
            Me.Width = CInt(scWidth)
            Me.Height = CInt(scHeight)
            Me.CenterToScreen()
            Form2.Top = Me.Top + 20
            Form2.Left = Me.Left + 20
        Else
            MsgBox("Size Not Acceptable")
        End If
    End Sub
    Private Sub Working_Click(sender As Object, e As EventArgs) Handles Button2.Click
        ' Retrieve the working rectangle from the Screen class
        ' using the PrimaryScreen and the WorkingArea properties. 
        Dim workingRectangle As System.Drawing.Rectangle = Screen.PrimaryScreen.WorkingArea
        ' Set the size of the form slightly less than size of 
        ' working rectangle.
        Me.Size = New System.Drawing.Size(workingRectangle.Width - 10, workingRectangle.Height - 10)
        ' Set the location so the entire form is visible.
        Me.Location = New System.Drawing.Point(10, 10)
    End Sub
    Private Sub Go2_Click(sender As Object, e As EventArgs) Handles Button4.Click
        'resize form2 from textboxes
        Dim scWidth As Long
        Dim scHeight As Long
        scWidth = CInt(TextBox1.Text)
        scHeight = CInt(TextBox2.Text)
        If scHeight >= 200 And scWidth >= 200 Then
            Form2.Width = CInt(scWidth)
            Form2.Height = CInt(scHeight)
            Form2.WindowState = FormWindowState.Normal
        Else
            MsgBox("Size Not Acceptable")
        End If
    End Sub
    Private Sub Exit_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Application.Exit()
    End Sub
    Private Sub Three_Click(sender As Object, e As EventArgs) Handles Button5.Click
        TextBox1.Text = "320"
        TextBox2.Text = "240"
        mPosition()
    End Sub
    Private Sub six_Click(sender As Object, e As EventArgs) Handles Button6.Click
        TextBox1.Text = "640"
        TextBox2.Text = "480"
    End Sub
    Private Sub Eight_Click(sender As Object, e As EventArgs) Handles Button7.Click
        TextBox1.Text = "800"
        TextBox2.Text = "600"
    End Sub
    Private Sub Thousand_Click(sender As Object, e As EventArgs) Handles Button8.Click
        TextBox1.Text = "1280"
        TextBox2.Text = "1024"
    End Sub
    Private Sub mPosition()
        Dim X As Integer = Button2.Left + Button2.Width + 40
        Dim Y As Integer = Button2.Top + 60
        Form2.StartPosition = FormStartPosition.Manual
        Form2.Location = New System.Drawing.Point(X, Y)
    End Sub
End Class

In the end the problem is to resize and move all the controls on the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.