Solved

Dynamically resizing controls when form changes size?

Posted on 2014-01-16
7
447 Views
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.
0
Comment
Question by:BlakeMcKenna
  • 4
  • 3
7 Comments
 
LVL 27

Expert Comment

by:MacroShadow
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


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
 

Author Comment

by:BlakeMcKenna
ID: 39786996
What about the Form_Resize() Event?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39787010
What about it?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:BlakeMcKenna
ID: 39787037
I guess not!

What about controls within controls?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39787066
Same logic applies.

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

Author Comment

by:BlakeMcKenna
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?
Screenshot.jpg
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 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.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating a route in asp.net webforms 2 25
get column names from table in vb.net 8 25
write xml in vb.net 2 24
VB.Net - MemoryMappedFiles - Confirm receipt 2 17
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now