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

This commit is contained in:
蓝点lilac
2020-11-24 05:14:23 +08:00
parent e28a663db7
commit aca5e163c1

View File

@@ -0,0 +1,21 @@
using System.Drawing;
using System.Windows.Forms;
namespace BulePointLilac.Methods
{
public static class TextBoxExtension
{
/// <summary>TextBox仿RichTextBox按住Ctrl加鼠标滚轮放缩字体</summary>
public static void CanResizeFont(this TextBox box)
{
box.MouseWheel += (sender, e) =>
{
if(Control.ModifierKeys != Keys.Control) return;
float size = box.Font.Size;
if(size < 8F && e.Delta < 0) return;
if(size > 40F && e.Delta > 0) return;
box.Font = new Font(box.Font.FontFamily, size + (e.Delta > 0 ? 1 : -1));
};
}
}
}