ToolStripFontSizeComboBox.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. namespace FastReport.Controls
  7. {
  8. internal class ToolStripFontSizeComboBox : ToolStripComboBox
  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 ComboBox_DrawItem(object sender, DrawItemEventArgs e)
  36. {
  37. e.DrawBackground();
  38. ComboBox.DrawImageAndText(e, null, Items[e.Index].ToString());
  39. }
  40. private void UpdateText()
  41. {
  42. updating = true;
  43. // mono fix
  44. ComboBox.SelectedIndex = 1;
  45. Text = Converter.DecreasePrecision(fontSize, 2).ToString();
  46. updating = false;
  47. }
  48. private void OnSizeSelected()
  49. {
  50. if (updating)
  51. return;
  52. if (SizeSelected != null)
  53. SizeSelected(this, EventArgs.Empty);
  54. }
  55. protected override void OnKeyDown(KeyEventArgs e)
  56. {
  57. if (e.KeyCode == Keys.Enter)
  58. OnSizeSelected();
  59. }
  60. protected override void OnSelectedIndexChanged(EventArgs e)
  61. {
  62. OnSizeSelected();
  63. }
  64. public ToolStripFontSizeComboBox()
  65. {
  66. ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
  67. ComboBox.ItemHeight = 15;
  68. ComboBox.DrawItem += ComboBox_DrawItem;
  69. Size = new Size(50, 25);
  70. Items.AddRange(new string[] {
  71. "5", "6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20",
  72. "22", "24", "26", "28", "36", "48", "72"});
  73. }
  74. }
  75. }