123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.ComponentModel;
- using FastReport.Utils;
- using FastReport.Design;
- namespace FastReport.Controls
- {
- internal class ToolStripFontSizeComboBox : ToolStripComboBox
- {
- private float fontSize;
- private bool updating;
- public new Control Owner { get; set; }
- public event EventHandler SizeSelected;
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public float FontSize
- {
- get
- {
- fontSize = Converter.StringToFloat(Text, true);
- UpdateText();
- return fontSize;
- }
- set
- {
- fontSize = value;
- UpdateText();
- }
- }
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public new System.Windows.Forms.ComboBox.ObjectCollection Items
- {
- get { return base.Items; }
- }
- public int ItemHeight
- {
- get => ComboBox.ItemHeight;
- set => ComboBox.ItemHeight = value;
- }
- private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
- {
- e.DrawBackground();
- if (e.Index != -1)
- {
- ComboBox.DrawImageAndText(e, null, Items[e.Index].ToString());
- }
- }
- private void UpdateText()
- {
- updating = true;
- // mono fix
- ComboBox.SelectedIndex = 1;
- Text = Converter.DecreasePrecision(fontSize, 2).ToString();
- updating = false;
- }
- private void OnSizeSelected()
- {
- if (updating)
- return;
- if (SizeSelected != null)
- SizeSelected(this, EventArgs.Empty);
- }
- protected override void OnKeyDown(KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- OnSizeSelected();
- }
- protected override void OnSelectedIndexChanged(EventArgs e)
- {
- OnSizeSelected();
- }
- public void UpdateDpiDependencies()
- {
- ItemHeight = Owner.LogicalToDevice(15);
- DropDownHeight = Owner.LogicalToDevice(300);
- }
- public void SetStyle(UIStyle style)
- {
- }
- public ToolStripFontSizeComboBox()
- {
- AutoSize = false;
- ComboBox.DrawMode = DrawMode.OwnerDrawFixed;
- ComboBox.ItemHeight = 15;
- ComboBox.DrawItem += ComboBox_DrawItem;
- Size = new Size(50, 25);
- Items.AddRange(new string[] {
- "6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20",
- "22", "24", "26", "28", "36", "48", "72"});
- }
- }
- }
|