Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

GET RELATIVE CONTROL POSITION TO FORM SIZE

Hi All,

I have a windows form.

1. Datagridview.
2. Flowlayoutpanel.

The form is set to maximize.

I want resize the datagridview control height from 0 to Flowlayoutpanel top location (relative to form).

How could I do it ?

Thank you.

Avatar of Deepak Lakkad
Deepak Lakkad
Flag of India image

Hi,

You can use following code to set width of DataGridView when form is resized.

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        DataGridView1.Width = FlowLayoutPanel1.Width
    End Sub

Open in new window


Same way you can set height of the DGV

- Deepak Lakkad
Avatar of emi_sastra
emi_sastra

ASKER

Hi deepaklakkad,

I don't want to set them at the same size.

I want to set the Datagridview height from 0 to FlowLayoutPanel1 relative top position to screen.

For example screen size = 1024 x 768

FlowLayoutPanel1.top  is at  1000 (this is relative position to form size), thus I want Datagridview.heigth = 990.

Thank you.
Select the FlowLayoutPanel and set its Dock property to Bottom.  Now adjust its Height in the Size property to the correct amount.

Now select the DataGridView and set its Dock property to Fill.
Hi Idle_Mind,

I have tried it like you said.
The DataGridView size cross the FlowLayoutPanel  area.

Thank you.
Docking is very finicky and sometimes cannot be "undone" when it has been done "out of order".  You need to add the FlowLayoutPanel and set its Dock to Bottom FIRST.

This may require you start with a BRAND NEW Form and add the FlowLayoutPanel and set Dock before you do the same with the DataGridView.
I've done at design time.
I also set anchor all direction to DataGridView

Thank you.
I meant still DataGridView size cross the FlowLayoutPanel  area.

Thank you.
Did you try by starting with a NEW form and then adding the FlowLayoutPanel FIRST?
I don't do that, since I have put it at design time.

Thank you.
I understand that.  The Dock property gets confused easily and you can't reliably change the "order" of docked items.

What I'm proposing is that you RECREATE the Form (at design-time) and be sure to add and dock the FlowLayoutPanel before the DataGridView.
Another problem is have also a FlowLayoutPanel (flp2) at the right side (vertical box).
When I dock flp1 to bottom, then it also cross the flp2 ?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok. It works.

Thank you very much for your help.