FontSizeComboBoxItem.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Windows.Forms;
  3. using System.ComponentModel;
  4. using FastReport.Utils;
  5. using FastReport.DevComponents.DotNetBar;
  6. using System.Drawing;
  7. using FastReport.Design;
  8. namespace FastReport.Controls
  9. {
  10. internal class FontSizeComboBoxItem : ComboBoxItem
  11. {
  12. private float fontSize;
  13. private bool updating;
  14. public Control Owner { get; set; }
  15. public event EventHandler SizeSelected;
  16. [Browsable(false)]
  17. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  18. public float FontSize
  19. {
  20. get
  21. {
  22. fontSize = Converter.StringToFloat(Text, true);
  23. UpdateText();
  24. return fontSize;
  25. }
  26. set
  27. {
  28. fontSize = value;
  29. UpdateText();
  30. }
  31. }
  32. [Browsable(false)]
  33. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  34. public new System.Windows.Forms.ComboBox.ObjectCollection Items
  35. {
  36. get { return base.Items; }
  37. }
  38. private void UpdateText()
  39. {
  40. updating = true;
  41. Text = Converter.DecreasePrecision(fontSize, 2).ToString();
  42. updating = false;
  43. }
  44. private void OnSizeSelected()
  45. {
  46. if (updating)
  47. return;
  48. if (SizeSelected != null)
  49. SizeSelected(this, EventArgs.Empty);
  50. }
  51. private void ComboBoxEx_KeyDown(object sender, KeyEventArgs e)
  52. {
  53. if (e.KeyCode == Keys.Enter)
  54. OnSizeSelected();
  55. }
  56. private void ComboBoxEx_SelectedIndexChanged(object sender, EventArgs e)
  57. {
  58. if (Enabled)
  59. OnSizeSelected();
  60. }
  61. private void ComboBoxEx_EnabledChanged(object sender, EventArgs e)
  62. {
  63. if (ComboBoxEx.Enabled)
  64. ComboBoxEx.DropDownStyle = ComboBoxStyle.DropDown;
  65. else
  66. {
  67. ComboBoxEx.DropDownStyle = ComboBoxStyle.DropDownList;
  68. ComboBoxEx.SelectedIndex = -1;
  69. }
  70. }
  71. public void SetStyle(UIStyle style)
  72. {
  73. Color controlColor = UIStyleUtils.GetControlColor(style);
  74. ComboBoxEx.DisabledBackColor = controlColor;
  75. }
  76. public new void UpdateDpiDependencies()
  77. {
  78. base.UpdateDpiDependencies();
  79. ItemHeight = Owner.LogicalToDevice(14);
  80. DropDownHeight = Owner.LogicalToDevice(300);
  81. }
  82. public FontSizeComboBoxItem()
  83. {
  84. ComboBoxEx.DropDownStyle = ComboBoxStyle.DropDown;
  85. ComboBoxEx.KeyDown += new KeyEventHandler(ComboBoxEx_KeyDown);
  86. ComboBoxEx.SelectedIndexChanged += new EventHandler(ComboBoxEx_SelectedIndexChanged);
  87. ComboBoxEx.EnabledChanged += new EventHandler(ComboBoxEx_EnabledChanged);
  88. ComboBoxEx.DrawMode = DrawMode.OwnerDrawVariable;
  89. ItemHeight = 14;
  90. ComboWidth = 40;
  91. Items.AddRange(new string[] {
  92. "5", "6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20",
  93. "22", "24", "26", "28", "36", "48", "72"});
  94. }
  95. }
  96. }