954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem in resizing controls (.Net 2008).

Hi,
we all know how to dock or anchor controls so that they resize themselves accordingly when a form is resized. It works fine till we have rows of controls on left and right size of the form. But what if have three columns (Columns as in visual sense. I'm not talking about any column control containing other controls) of controls? For example a form having a bunch of controls in the left side, a bunch in the middle and a bunch in the right. There may be a few more bunches in the middle. Now while resizing the form, I want the controls to resize accordingly as well as change their positions to make space for the previous bunch of controls that are resizing.
I mean, while the user increases the form size horizontally, the controls of the second bunch should resize and at the same time they should move right because the controls of the first bunch are increasing horizontally too. When the user decreases the form size horizontally the same thing should occur in the reverse order.
I can manage it somehow using nested splitcontainers but that's too cumbersome. I would like to know if there's some better way to achieve it, like setting some property etc.?
Please help. Check the attached image. Please feel free to ask if my post isn't comprehensible. Regards.

Attachments Untitled.jpg 24.64KB Untitled2.jpg 39.04KB
priyamtheone
Newbie Poster
22 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

I do not believe that there is such a Property, unless you create one.:)

See if this helps otherwise.
3 Panels (including Labels and TextBoxes as your attached images)

Public Class Form1
    Private iWidth As Integer = 0 '// used to resize.

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        iWidth = CInt((Me.ClientRectangle.Width - 20) / 3) '// change the "-20" to work as needed for your project.
        Panel1.Width = iWidth : Panel2.Width = iWidth : Panel3.Width = iWidth '// resize Panels.
        Panel2.Left = Panel1.Left + Panel1.Width + 5 : Panel3.Left = Panel2.Left + Panel2.Width + 5 '// set Panels New Locations.
        resizeTextBoxes(Panel1) : resizeTextBoxes(Panel2) : resizeTextBoxes(Panel3) '// resize TextBoxes in Panels.
    End Sub

    Private Sub resizeTextBoxes(ByVal selectedPanel As Panel)
        For Each ctl As Control In selectedPanel.Controls
            If TypeOf ctl Is TextBox Then ctl.Width = (selectedPanel.Width - ctl.Left) - 5 '//  "-5" accumulates the space of TextBox and end of Panel.
        Next
    End Sub
End Class
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 


I would use a TableLayoutControl.

6 Columns and 5 Rows.

Columns 1,3,5 would be absolute widths. The Label width
Columns 2,4,6 would be percentage widths of 33.33%

Set the row heights to absolute.

Dock the textboxes to the top of the cells.

It will do exactly what you want.

Unhnd_Exception
Posting Pro
570 posts since Nov 2010
Reputation Points: 249
Solved Threads: 201
 

Thanks to both @codeorder and @Unhnd_Exception

priyamtheone
Newbie Poster
22 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: