Solved

Dynamically resizing controls when form changes size?

Posted on 2014-01-16
7
441 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 26

Expert Comment

by:MacroShadow
Comment Utility
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
Comment Utility
What about the Form_Resize() Event?
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
What about it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:BlakeMcKenna
Comment Utility
I guess not!

What about controls within controls?
0
 
LVL 26

Expert Comment

by:MacroShadow
Comment Utility
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
Comment Utility
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 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

10 Experts available now in Live!

Get 1:1 Help Now