Reputation: 8036
I have a Windows form which contains a grid of PictureBox controls. I want to be able to resize the entire form at runtime and have all of these PictureBox controls dynamically resize (scale) proportionally to accommodate the form's new size. The goal is to avoid having to make separate resource files that would essentially make use of the same .cs file just because I want different sizes.
Upvotes: 1
Views: 1578
Reputation: 20703
Trying using a TableLayoutPanel
control with all rows and columns in percent mode.
new Form {
Controls = {
new TableLayoutPanel {
Dock = DockStyle.Fill,
ColumnCount = 2,
Controls = {
new Button {Text = "0,0", Dock = DockStyle.Fill},
new Button {Text = "1,0", Dock = DockStyle.Fill},
new Button {Text = "0,1", Dock = DockStyle.Fill},
new Button {Text = "1,1", Dock = DockStyle.Fill}
},
RowStyles = {
new RowStyle(SizeType.Percent) {Height = 1},
new RowStyle(SizeType.Percent) {Height = 1}
},
ColumnStyles = {
new ColumnStyle(SizeType.Percent) {Width = 1},
new ColumnStyle(SizeType.Percent) {Width = 1}
}
}
}
}.ShowDialog();
Upvotes: 3