将TextBox鼠标滚轮缩放字体写为扩展方法

This commit is contained in:
蓝点lilac
2020-11-24 05:19:58 +08:00
parent 831289fb63
commit 6dbe4daf90

View File

@@ -40,7 +40,7 @@ namespace BulePointLilac.Controls
this.MinimumSize = this.Size = new Size(400, 150).DpiZoom();
this.MaximizeBox = MinimizeBox = ShowIcon = ShowInTaskbar = false;
this.Controls.AddRange(new Control[] { TxtInput, BtnOk, BtnCancel });
TxtInput.MouseWheel += ResizeFont;
TxtInput.CanResizeFont();
InitializeComponents();
}
@@ -81,16 +81,6 @@ namespace BulePointLilac.Controls
BtnOk.Left = BtnCancel.Left - BtnOk.Width - a;
this.OnResize(null);
}
/// <summary>缩放文本框字体</summary>
private void ResizeFont(object sender, MouseEventArgs e)
{
if(ModifierKeys != Keys.Control) return;
float size = TxtInput.Font.Size;
if(size < 8F && e.Delta < 0) return;
if(size > 40F && e.Delta > 0) return;
TxtInput.Font = new Font(TxtInput.Font.FontFamily, size + (e.Delta > 0 ? 1 : -1));
}
}
}
}