Go Premium for a chance to win a PS4. Enter to Win


Dynamically resizing controls when form changes size?

Posted on 2014-01-16
Medium Priority
Last Modified: 2014-01-16
Does anyone know how to resize controls within a form when a user changes the size of the form. I want the controls to resize proportionately as the form size changes.
Question by:BlakeMcKenna
  • 4
  • 3
LVL 28

Expert Comment

ID: 39786971
Take a look at the .Anchor property of pretty much any control. This resizes the control any time the parent is resized. The way I learned how to use the .Anchor properly was I started a blank project and added just about every control and used differnet anchors like: Left and Right or Left and Top, and see what happened when I maximized my form.

Edit - Start a new project and add a Datagridview, Button, and Textbox. Then press F7 and add this:

Option Strict On
Option Explicit On
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        With Me
            .Text = "Anchor Test"
            .Size = New Size(300, 300)
        End With
        With DataGridView1
            .Location = New Point(13, 13)
            .Size = New Size(259, 208)
            .Anchor = AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top Or AnchorStyles.Bottom
        End With
        With Button1
            .Location = New Point(12, 227)
            .Size = New Size(75, 23)
            .Anchor = AnchorStyles.Bottom Or AnchorStyles.Left
        End With
        With TextBox1
            .Location = New Point(93, 229)
            .Size = New Size(179, 20)
            .Anchor = AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Left
        End With
    End Sub
End Class

Open in new window


Author Comment

ID: 39786996
What about the Form_Resize() Event?
LVL 28

Expert Comment

ID: 39787010
What about it?
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 39787037
I guess not!

What about controls within controls?
LVL 28

Expert Comment

ID: 39787066
Same logic applies.

Use the .Anchor property of the parent control, and within it the .Anchor property of the child control.

Author Comment

ID: 39787086
Sorry but I'm not following! I have attached an image of the Form I need to do this with. Can you be more specific plz?
LVL 28

Accepted Solution

MacroShadow earned 2000 total points
ID: 39787224
Set up your form and all of its controls, based on the above example set the location, size and anchor  of each control.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question