ToolStripFontSizeComboBox.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. using System.ComponentModel;
  5. using FastReport.Utils;
  6. using FastReport.Design;
  7. namespace FastReport.Controls
  8. {
  9. internal class ToolStripFontSizeComboBox : ToolStripComboBox
  10. {
  11. private float fontSize;
  12. private bool updating;
  13. public new Control Owner { get; set; }
  14. public event EventHandler SizeSelected;
  15. [Browsable(false)]
  16. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  17. public float FontSize
  18. {
  19. get
  20. {
  21. fontSize = Converter.StringToFloat(Text, true);
  22. UpdateText();
  23. return fontSize;
  24. }
  25. set
  26. {
  27. fontSize = value;
  28. UpdateText();
  29. }
  30. }
  31. [Browsable(false)]
  32. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  33. public new System.Windows.Forms.ComboBox.ObjectCollection Items
  34. {
  35. get { return base.Items; }
  36. }
  37. public int ItemHeight
  38. {
  39. get => ComboBox.ItemHeight;
  40. set => ComboBox.ItemHeight = value;
  41. }
  42. private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
  43. {
  44. e.DrawBackground();
  45. if (e.Index != -1)
  46. {
  47. ComboBox.DrawImageAndText(e, null, Items[e.Index].ToString());
  48. }
  49. }
  50. private void UpdateText()
  51. {
  52. updating = true;
  53. // mono fix
  54. ComboBox.SelectedIndex = 1;
  55. Text = Converter.DecreasePrecision(fontSize, 2).ToString();
  56. updating = false;
  57. }
  58. private void OnSizeSelected()
  59. {
  60. if (updating)
  61. return;
  62. if (SizeSelected != null)
  63. SizeSelected(this, EventArgs.Empty);
  64. }
  65. protected override void OnKeyDown(KeyEventArgs e)
  66. {
  67. if (e.KeyCode == Keys.Enter)
  68. OnSizeSelected();
  69. }
  70. protected override void OnSelectedIndexChanged(EventArgs e)
  71. {
  72. OnSizeSelected();
  73. }
  74. public void UpdateDpiDependencies()
  75. {
  76. ItemHeight = Owner.LogicalToDevice(15);
  77. DropDownHeight = Owner.LogicalToDevice(300);
  78. }
  79. public void SetStyle(UIStyle style)
  80. {
  81. }
  82. public ToolStripFontSizeComboBox()
  83. {
  84. AutoSize = false;
  85. ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
  86. ComboBox.ItemHeight = 15;
  87. ComboBox.DrawItem += ComboBox_DrawItem;
  88. Size = new Size(50, 25);
  89. Items.AddRange(new string[] {
  90. "6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20",
  91. "22", "24", "26", "28", "36", "48", "72"});
  92. }
  93. }
  94. }