Skip to content

Instantly share code, notes, and snippets.

@blahlicus
Created June 26, 2016 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blahlicus/f6a01a0c692ff5ae0772072297040442 to your computer and use it in GitHub Desktop.
Save blahlicus/f6a01a0c692ff5ae0772072297040442 to your computer and use it in GitHub Desktop.
partial class FilledForm : Form
{
void InitializeComponent()
{
Title = "Test Form";
ClientSize = new Size(1920, 1080);
var tlMain = new TableLayout();
var trRow = new TableRow();
trRow.ScaleHeight = true;
tlMain.Rows.Add(trRow);
var tcCell = new TableCell();
tcCell.ScaleWidth = true;
trRow.Cells.Add(tcCell);
var btnMain = new Button();
btnMain.Text = "This button fills the entire form";
trCell.Control = btnMain;
Content = tlMain;
}
}
partial class HalfFilledForm : Form
{
void InitializeComponent()
{
Title = "Test Form";
ClientSize = new Size(1920, 1080);
var tlMain = new TableLayout();
var trRow = new TableRow();
trRow.ScaleHeight = true;
tlMain.Rows.Add(trRow);
var tcCell = new TableCell();
tcCell.ScaleWidth = true;
trRow.Cells.Add(tcCell);
var btnMain = new Button();
btnMain.Text = "This button occupies the left half of the form";
tcCell.Control = btnMain;
// adding another cell to the table row and setting both cells' ScaleWidth property to true evenly divides screen spaces between the two of them
// you may add more cells in front and behind of your "main" element as spacers.
var tcSpacer = new TableCell();
tcSpacer.ScaleWidth = true;
tcSpacer.Control = null; // <-- set the content of a cell as null and set ScaleWidth as true to create empty spaces with TableLayout
trRow.Cells.Add(tcSpacer);
Content = tlMain;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment