TextBoxExtension.cs 691 B

123456789101112131415161718192021
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace BluePointLilac.Methods
  4. {
  5. public static class TextBoxExtension
  6. {
  7. /// <summary>TextBox仿RichTextBox按住Ctrl加鼠标滚轮放缩字体</summary>
  8. public static void CanResizeFont(this TextBox box)
  9. {
  10. box.MouseWheel += (sender, e) =>
  11. {
  12. if(Control.ModifierKeys != Keys.Control) return;
  13. float size = box.Font.Size;
  14. if(size < 8F && e.Delta < 0) return;
  15. if(size > 40F && e.Delta > 0) return;
  16. box.Font = new Font(box.Font.FontFamily, size + (e.Delta > 0 ? 1 : -1));
  17. };
  18. }
  19. }
  20. }