Docking 2 controls to share space

  • Thread starter Thread starter Scott Hodson
  • Start date Start date
S

Scott Hodson

I have two data grids, 1 on the left of a form and 1 on the right side, and
as I expand the size of the form I would like them both to fill the new
space, each grid always taking up 50% of the available space.

I tried this setting both of their Dock properties to Fill but they both
take up 100% of the form. I tried setting the anchoring differently as well
but to no avail. I'm not sure how to make these two grids equally share the
available screen space as the size of the form changes.
 
Override the Form.Layout event and reposition your controls.

protected override void OnLayout(LayoutEventArgs levent)

{

this.dataGrid1.Location=new Point(0,0);

this.dataGrid1.Size=new
Size(this.ClientSize.Width/2,this.ClientSize.Height);

this.dataGrid2.Location=new Point(this.ClientSize.Width/2,0);

this.dataGrid2.Size=new
Size(this.ClientSize.Width/2,this.ClientSize.Height);

base.OnLayout (levent);

}


--
Bob Powell [MVP]
C#, System.Drawing

ANNOUNCING: Well Formed.
The monthy electronic magazine for
Windows Forms and GDI+ engineers
http://www.bobpowell.net/wellformed.htm

Check out the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
 
Back
Top