Vertical align the data control
This commit is contained in:
parent
fa74291e39
commit
8e21ddffc9
@ -18,16 +18,24 @@ public partial class Setting : UserControl
|
|||||||
this.labelSettingName.Text = settingMetaData.SettingName();
|
this.labelSettingName.Text = settingMetaData.SettingName();
|
||||||
this.labelExplanation.Text = settingMetaData.SettingExplanation();
|
this.labelExplanation.Text = settingMetaData.SettingExplanation();
|
||||||
|
|
||||||
// Calculate the needed height of the explanation label when the parent window is resized:
|
var dataControl = settingMetaData.SetupDataControl();
|
||||||
|
this.tableLayout.Controls.Add(dataControl, 2, 0);
|
||||||
|
|
||||||
|
// Ensure, that this data control is vertical centered by calculating the needed margin, considering the outer size of the table layout:
|
||||||
|
var margin = (this.tableLayout.GetRowHeights().First() - dataControl.Height) / 2f;
|
||||||
|
dataControl.Margin = new Padding(0, (int) margin, 0, (int)margin);
|
||||||
|
|
||||||
|
// Calculate the needed height of the explanation label & centering of the data control when the parent window is resized:
|
||||||
this.tableLayout.Resize += (sender, args) =>
|
this.tableLayout.Resize += (sender, args) =>
|
||||||
{
|
{
|
||||||
// Adjust the height of the parent controls (table & user control):
|
// Adjust the height of the parent controls (table & user control):
|
||||||
this.tableLayout.Height = Math.Max((int)this.labelExplanation.CreateGraphics().MeasureString(this.labelExplanation.Text, this.labelExplanation.Font, new SizeF(this.labelExplanation.Width, 1000)).Height, 66);
|
this.tableLayout.Height = Math.Max((int)this.labelExplanation.CreateGraphics().MeasureString(this.labelExplanation.Text, this.labelExplanation.Font, new SizeF(this.labelExplanation.Width, 1000)).Height, 66);
|
||||||
this.Height = this.tableLayout.Height + this.tableLayout.Margin.Vertical;
|
this.Height = this.tableLayout.Height + this.tableLayout.Margin.Vertical;
|
||||||
};
|
|
||||||
|
|
||||||
var dataControl = settingMetaData.SetupDataControl();
|
// Ensure, that this data control is vertical centered by calculating the needed margin, considering the outer size of the table layout:
|
||||||
this.tableLayout.Controls.Add(dataControl, 2, 0);
|
var margin = (this.tableLayout.GetRowHeights().First() - dataControl.Height) / 2f;
|
||||||
|
dataControl.Margin = new Padding(0, (int) margin, 0, (int)margin);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly record struct SettingUIData(
|
private readonly record struct SettingUIData(
|
||||||
|
Loading…
Reference in New Issue
Block a user