diff --git a/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.Designer.cs b/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.Designer.cs index 8b5f0054a..04c9e8477 100644 --- a/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.Designer.cs +++ b/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.Designer.cs @@ -51,7 +51,6 @@ private void InitializeComponent() 0, 0}); this.nudWidth.Name = "nudWidth"; - this.nudWidth.ValueChanged += new System.EventHandler(this.nudWidth_ValueChanged); // // nudHeight // @@ -62,7 +61,6 @@ private void InitializeComponent() 0, 0}); this.nudHeight.Name = "nudHeight"; - this.nudHeight.ValueChanged += new System.EventHandler(this.nudHeight_ValueChanged); // // lblWidth // @@ -77,8 +75,11 @@ private void InitializeComponent() // cbAspectRatio // resources.ApplyResources(this.cbAspectRatio, "cbAspectRatio"); + this.cbAspectRatio.Checked = true; + this.cbAspectRatio.CheckState = System.Windows.Forms.CheckState.Checked; this.cbAspectRatio.Name = "cbAspectRatio"; this.cbAspectRatio.UseVisualStyleBackColor = true; + this.cbAspectRatio.CheckedChanged += new System.EventHandler(this.cbAspectRatio_CheckedChanged); // // btnOK // diff --git a/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.cs b/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.cs index 7d5e23aae..c6e08e49f 100644 --- a/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/ImageSizeForm.cs @@ -39,17 +39,26 @@ public partial class ImageSizeForm : Form { public Size Result { get; private set; } - public ImageSizeForm() + private double widthRatio, heightRatio; + private bool ignoreValueChanged = true; + + public ImageSizeForm(Size size) { InitializeComponent(); Icon = ShareXResources.Icon; - } - public ImageSizeForm(Size size) : this() - { Result = size; + widthRatio = (double)size.Width / size.Height; + heightRatio = (double)size.Height / size.Width; + nudWidth.SetValue(size.Width); nudHeight.SetValue(size.Height); + VerifySize(); + + nudWidth.TextChanged += NudWidth_TextChanged; + nudHeight.TextChanged += NudHeight_TextChanged; + + ignoreValueChanged = false; } private void VerifySize() @@ -57,19 +66,54 @@ private void VerifySize() btnOK.Enabled = nudWidth.Value > 0 && nudHeight.Value > 0; } + private void ApplyWidthAspectRatio() + { + if (!ignoreValueChanged) + { + if (cbAspectRatio.Checked) + { + ignoreValueChanged = true; + nudHeight.Value = (int)Math.Round((double)nudWidth.Value * heightRatio); + ignoreValueChanged = false; + } + + VerifySize(); + } + } + + private void ApplyHeightAspectRatio() + { + if (!ignoreValueChanged) + { + if (cbAspectRatio.Checked) + { + ignoreValueChanged = true; + nudWidth.Value = (int)Math.Round((double)nudHeight.Value * widthRatio); + ignoreValueChanged = false; + } + + VerifySize(); + } + } + private void ResizeSizeForm_Shown(object sender, EventArgs e) { this.ForceActivate(); } - private void nudWidth_ValueChanged(object sender, EventArgs e) + private void NudWidth_TextChanged(object sender, EventArgs e) { - VerifySize(); + ApplyWidthAspectRatio(); } - private void nudHeight_ValueChanged(object sender, EventArgs e) + private void NudHeight_TextChanged(object sender, EventArgs e) { - VerifySize(); + ApplyHeightAspectRatio(); + } + + private void cbAspectRatio_CheckedChanged(object sender, EventArgs e) + { + ApplyWidthAspectRatio(); } private void btnOK_Click(object sender, EventArgs e)