You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.3 KiB

1 month ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Reflection;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading;
  13. using System.Windows.Forms;
  14. namespace Customize.Controls
  15. {
  16. public static class ControlHelper
  17. {
  18. /// <summary>
  19. /// 设置GDI高质量模式抗锯齿
  20. /// </summary>
  21. /// <param name="g">The g.</param>
  22. public static void SetGDIHigh(this Graphics g)
  23. {
  24. g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
  25. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  26. g.CompositingQuality = CompositingQuality.HighQuality;
  27. }
  28. /// <summary>
  29. /// Creates the rounded rectangle path.
  30. /// </summary>
  31. /// <param name="rect">The rect.</param>
  32. /// <param name="cornerRadius">The corner radius.</param>
  33. /// <returns>GraphicsPath.</returns>
  34. public static GraphicsPath CreateRoundedRectanglePath(this RectangleF rect, int cornerRadius)
  35. {
  36. GraphicsPath roundedRect = new GraphicsPath();
  37. roundedRect.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
  38. roundedRect.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
  39. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
  40. roundedRect.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);
  41. roundedRect.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);
  42. roundedRect.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
  43. roundedRect.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
  44. roundedRect.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
  45. roundedRect.CloseFigure();
  46. return roundedRect;
  47. }
  48. }
  49. }