• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Dynamically resizing controls when form changes size?

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.
0
BlakeMcKenna
Asked:
BlakeMcKenna
  • 4
  • 3
1 Solution
 
MacroShadowCommented:
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


http://www.vbforums.com/showthread.php?689453-Resize-the-controls-on-windows-form-when-the-form-is-maximed-or-in-normal-state&p=4226571&viewfull=1#post4226571
0
 
BlakeMcKennaAuthor Commented:
What about the Form_Resize() Event?
0
 
MacroShadowCommented:
What about it?
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
BlakeMcKennaAuthor Commented:
I guess not!

What about controls within controls?
0
 
MacroShadowCommented:
Same logic applies.

Use the .Anchor property of the parent control, and within it the .Anchor property of the child control.
0
 
BlakeMcKennaAuthor Commented:
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?
Screenshot.jpg
0
 
MacroShadowCommented:
Set up your form and all of its controls, based on the above example set the location, size and anchor  of each control.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now