Fixing the window sizes

This commit is contained in:
Matt Neumann 2025-03-05 10:07:49 -08:00
parent 34e44def21
commit 1a0cc36907
2 changed files with 37 additions and 13 deletions

View File

@ -11,12 +11,34 @@ namespace Better_NCP_Editor
public EditValueForm(string propertyName, string currentValue, Type valueType) public EditValueForm(string propertyName, string currentValue, Type valueType)
{ {
// Set form properties. // Set the minimum size.
this.MinimumSize = new Size(210, 150); // Example: 300x150 pixels
// Optionally, set the default size if you want:
this.ClientSize = new Size(210, 150);
// Measure the width of the property name.
Size keySize = TextRenderer.MeasureText(propertyName, this.Font);
// Determine the width required for the input control.
int inputWidth = 0;
if (valueType == typeof(bool))
{
// For a boolean, we'll use the longer of "true" or "false" plus padding.
inputWidth = TextRenderer.MeasureText("false", this.Font).Width + 30;
}
else
{
inputWidth = TextRenderer.MeasureText(currentValue, this.Font).Width + 20;
}
// Determine the desired width: the maximum of the key width and input width, plus extra padding.
int desiredWidth = Math.Max(keySize.Width, inputWidth) + 40;
// Set the form's client size (you can also set MinimumSize here if needed).
this.ClientSize = new Size(desiredWidth, 120);
this.Text = $"Edit {propertyName}"; this.Text = $"Edit {propertyName}";
this.StartPosition = FormStartPosition.CenterParent; this.StartPosition = FormStartPosition.CenterParent;
this.ClientSize = new Size(250, 120);
// Label for the property. // Create the property label.
Label lblProperty = new Label() Label lblProperty = new Label()
{ {
Text = propertyName, Text = propertyName,
@ -25,13 +47,14 @@ namespace Better_NCP_Editor
}; };
this.Controls.Add(lblProperty); this.Controls.Add(lblProperty);
// Create the appropriate input control. // Create the input control with width based on desiredWidth minus margins.
int controlWidth = desiredWidth - 20;
if (valueType == typeof(bool)) if (valueType == typeof(bool))
{ {
ComboBox combo = new ComboBox() ComboBox combo = new ComboBox()
{ {
Location = new Point(10, 40), Location = new Point(10, 40),
Width = 200, Width = controlWidth,
DropDownStyle = ComboBoxStyle.DropDownList DropDownStyle = ComboBoxStyle.DropDownList
}; };
combo.Items.Add("true"); combo.Items.Add("true");
@ -45,7 +68,7 @@ namespace Better_NCP_Editor
TextBox txtBox = new TextBox() TextBox txtBox = new TextBox()
{ {
Location = new Point(10, 40), Location = new Point(10, 40),
Width = 200, Width = controlWidth,
Text = currentValue Text = currentValue
}; };
inputControl = txtBox; inputControl = txtBox;
@ -57,7 +80,9 @@ namespace Better_NCP_Editor
{ {
Text = "OK", Text = "OK",
Location = new Point(10, 80), Location = new Point(10, 80),
DialogResult = DialogResult.OK Size = new Size(80, 25),
DialogResult = DialogResult.OK,
Anchor = AnchorStyles.Left | AnchorStyles.Bottom
}; };
btnOk.Click += BtnOk_Click; btnOk.Click += BtnOk_Click;
this.Controls.Add(btnOk); this.Controls.Add(btnOk);
@ -66,13 +91,12 @@ namespace Better_NCP_Editor
Button btnCancel = new Button() Button btnCancel = new Button()
{ {
Text = "Cancel", Text = "Cancel",
Location = new Point(120, 80), Location = new Point(100, 80), // Positioned to the right of OK.
DialogResult = DialogResult.Cancel Size = new Size(80, 25),
DialogResult = DialogResult.Cancel,
Anchor = AnchorStyles.Left | AnchorStyles.Bottom
}; };
this.Controls.Add(btnCancel); this.Controls.Add(btnCancel);
this.AcceptButton = btnOk;
this.CancelButton = btnCancel;
} }
private void BtnOk_Click(object sender, EventArgs e) private void BtnOk_Click(object sender, EventArgs e)

View File

@ -27,7 +27,7 @@ namespace Better_NCP_Editor
entityTreeView.AfterSelect += entityTreeView_AfterSelect; entityTreeView.AfterSelect += entityTreeView_AfterSelect;
// Prevent the form from shrinking below its current size. // Prevent the form from shrinking below its current size.
this.MinimumSize = new Size(1045, 700); // Set minimum allowed size this.MinimumSize = new Size(1194, 928); // Set minimum allowed size
this.FormBorderStyle = FormBorderStyle.Sizable; this.FormBorderStyle = FormBorderStyle.Sizable;
// Example layout using docking: // Example layout using docking: