views:

100

answers:

1

I have two DataGridView controls, with three buttons in between them vertically, in a VB 2005 form that need to be resized and moved around on a form resize.

The code below works, and does what I want. It takes the difference between the new size and the default size, splits the height difference between the two DataGridViews, and moves things around correctly.

What bugs me about it is that I've hard-coded the defaults into the ResizeEnd handler. How would I go about passing the default size so that I don't repeat myself?

Even better, is there a way to do it with anchoring, docking, and other stuff, so that I don't even need to write code?

Thanks in advance!

    Private Sub dlgShowAssets_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd


    Dim defaultWindowSize As New System.Drawing.Size(759, 619)
    Dim defaultAssetDGVSize As New System.Drawing.Size(730, 153)
    Dim defaultAssetDGVPos As New System.Drawing.Point(9, 186)

    Dim defaultButton1Pos As New System.Drawing.Point(9, 345)
    Dim defaultButton2Pos As New System.Drawing.Point(100, 345)
    Dim defaultButton3Pos As New System.Drawing.Point(191, 345)

    Dim defaultDetailDGVSize As New System.Drawing.Size(730, 177)
    Dim defaultDetailDGVPos As New System.Drawing.Point(9, 374)

    Dim deltaX As Integer = Me.Size.Width - defaultWindowSize.Width
    Dim deltaY As Integer = Me.Size.Height - defaultWindowSize.Height
    Dim deltaSize As New System.Drawing.Size(deltaX, deltaY / 2)
    Dim deltaPos As New System.Drawing.Point(0, deltaY / 2)


    Me.AssetDataGridView.Size = defaultAssetDGVSize + deltaSize

    Me.btnAddAsset.Location = defaultButton1Pos + deltaPos
    Me.btnEditAsset.Location = defaultButton2Pos + deltaPos
    Me.btnDeleteAsset.Location = defaultButton3Pos + deltaPos

    Me.AssetIdentifierDataGridView.Size = defaultDetailDGVSize + deltaSize
    Me.AssetIdentifierDataGridView.Location = defaultDetailDGVPos + deltaPos

End Sub
+1  A: 

You can use the TableLayoutPanel control.

Bingo! Thank you!
John at CashCommons
Just a follow-up -- that suggestion probably made me 5,000% more productive in this task. I may be able to make all of the forms in my app resizable tonight. Thanks again!
John at CashCommons