Vertical align the data control
This commit is contained in:
parent
fa74291e39
commit
8e21ddffc9
@ -17,17 +17,25 @@ public partial class Setting : UserControl
|
||||
this.labelIcon.Image = settingMetaData.Icon;
|
||||
this.labelSettingName.Text = settingMetaData.SettingName();
|
||||
this.labelExplanation.Text = settingMetaData.SettingExplanation();
|
||||
|
||||
var dataControl = settingMetaData.SetupDataControl();
|
||||
this.tableLayout.Controls.Add(dataControl, 2, 0);
|
||||
|
||||
// Calculate the needed height of the explanation label when the parent window is resized:
|
||||
// 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) =>
|
||||
{
|
||||
// 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.Height = this.tableLayout.Height + this.tableLayout.Margin.Vertical;
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
var dataControl = settingMetaData.SetupDataControl();
|
||||
this.tableLayout.Controls.Add(dataControl, 2, 0);
|
||||
}
|
||||
|
||||
private readonly record struct SettingUIData(
|
||||
|
Loading…
Reference in New Issue
Block a user