Author Topic: Resizing Controls at runtime  (Read 1426 times)

yubish

  • Newbie
  • *
  • Posts: 11
    • View Profile
Resizing Controls at runtime
« on: May 04, 2015, 05:02:35 AM »
Hey Guys,
I'm trying to build an app with AdvancedHMI where i can move components and resize them during the execution of the app.
So far i found a way to do it for normal controls and advancedHMI controls, but when i try to apply it to a userControl, it works, but the controls inside it remain with their same respective sizes. And all i see is the borders of the usercontrol that are changing
I want to know if there is a way to make the components of a usercontrol change their size when the usercontrol's size change.
I tried this code and it works but it's very painful to find the good proportion and the good and it's really horrible.


Code: [Select]
    Private Sub UserControl1(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
        PictureBox1.Height = Me.Height / 3
        PictureBox1.Width = Me.Width / 3
        PictureBox2.Height = Me.Height / 3
        PictureBox2.Width = Me.Width / 3
        Button1.Height = Me.Height / 5
        Button1.Width = Me.Width / 5
    End Sub

Thanks in advance

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Resizing Controls at runtime
« Reply #1 on: May 04, 2015, 08:27:49 PM »
Anchor property of the components within User Control might help to a certain degree.

You can read more here:

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

and here:

http://www.homeandlearn.co.uk/NET/nets13p1.html

and bunch of other websites that Google search might show.

Using a FlowLayoutPanel and/or TableLayoutPanel might also help to a degree, check this link:

http://stackoverflow.com/questions/7223013/is-it-possible-to-anchor-a-control-to-another-control
« Last Edit: May 04, 2015, 09:59:09 PM by Godra »