FontSizeComboBoxItem.cs 2.7 KB

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