FDButton.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing.Drawing2D;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  10. using System.Windows.Forms;
  11. using ZedGraph;
  12. namespace ImpulseVision
  13. {
  14. public partial class RoundingButtonsComponent : Component
  15. {
  16. public Form TargetForm { get; set; }
  17. private bool roundingEnable = false;
  18. [Description("Вкл/Выкл закругление объекта")]
  19. public bool RoundingEnable
  20. {
  21. get => roundingEnable;
  22. set
  23. {
  24. roundingEnable = value;
  25. Update();
  26. }
  27. }
  28. private int roundingPercent = 100;
  29. [DisplayName("Rounding [%]")]
  30. [DefaultValue(100)]
  31. [Description("Указывает радиус закругления объекта в процентном соотношении")]
  32. public int Rounding
  33. {
  34. get => roundingPercent;
  35. set
  36. {
  37. if (value >= 0 && value <= 100)
  38. {
  39. roundingPercent = value;
  40. Update();
  41. }
  42. }
  43. }
  44. [DefaultValue(true)]
  45. [Description("Применять закругление для вложенных контейнеров")]
  46. public bool NestedContainers { get; set; } = true;
  47. public RoundingButtonsComponent()
  48. {
  49. InitializeComponent();
  50. }
  51. public RoundingButtonsComponent(IContainer container)
  52. {
  53. Update();
  54. container.Add(this);
  55. InitializeComponent();
  56. }
  57. public void Update()
  58. {
  59. if (TargetForm != null && TargetForm.Controls.Count > 0)
  60. {
  61. DefineRounding(TargetForm.Controls);
  62. }
  63. }
  64. public void DefineRounding(Control.ControlCollection controls)
  65. {
  66. foreach (Control ctrl in controls)
  67. {
  68. if (ctrl is yt_Button)
  69. {
  70. yt_Button btn = (yt_Button)ctrl;
  71. btn.RoundingEnable = RoundingEnable;
  72. btn.Rounding = Rounding;
  73. btn.Refresh();
  74. }
  75. if (NestedContainers)
  76. {
  77. if (ctrl.Controls.Count > 0)
  78. {
  79. DefineRounding(ctrl.Controls);
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }