123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- namespace System.Windows.Forms
- {
- public class ToolStripComboBox : ToolStripItem
- {
- public ComboBoxBase ComboBox { get; }
- public ComboBoxStyle DropDownStyle
- {
- get => ComboBox.DropDownStyle;
- set => ComboBox.DropDownStyle = value;
- }
- public override string Text
- {
- get => ComboBox.Text;
- set => ComboBox.Text = value;
- }
- public int ItemHeight
- {
- get => ComboBox.ItemHeight;
- set => ComboBox.ItemHeight = value;
- }
- public bool IntegralHeight
- {
- get => ComboBox.IntegralHeight;
- set => ComboBox.IntegralHeight = value;
- }
- public DrawMode DrawMode
- {
- get => ComboBox.DrawMode;
- set => ComboBox.DrawMode = value;
- }
- public int DropDownWidth
- {
- get => ComboBox.DropDownWidth;
- set => ComboBox.DropDownWidth = value;
- }
- public int DropDownHeight
- {
- get => ComboBox.DropDownHeight;
- set => ComboBox.DropDownHeight = value;
- }
- public int MaxDropDownItems
- {
- get => ComboBox.MaxDropDownItems;
- set => ComboBox.MaxDropDownItems = value;
- }
- public ListControl.ObjectCollection Items => ComboBox.Items;
- public int SelectedIndex
- {
- get => ComboBox.SelectedIndex;
- set => ComboBox.SelectedIndex = value;
- }
- public object SelectedItem
- {
- get => ComboBox.SelectedItem;
- set => ComboBox.SelectedItem = value;
- }
- public bool Sorted
- {
- get => ComboBox.Sorted;
- set => ComboBox.Sorted = value;
- }
- public event EventHandler SelectedIndexChanged;
- public event EventHandler SelectedValueChanged;
- protected override void SetControlHeight(int value) { }
- protected virtual void OnSelectedIndexChanged(EventArgs e) => SelectedIndexChanged?.Invoke(this, e);
-
- protected virtual void OnSelectedValueChanged(EventArgs e) => SelectedValueChanged?.Invoke(this, e);
- public override void ApplyStyle(ToolStripProfessionalRenderer r)
- {
- var combo = ComboBox.control;
- combo.Foreground = r.Foreground;
- combo.Resources["ComboBox.Static.Background"] = r.ComboBoxStaticBackground;
- combo.Resources["ComboBox.Static.Border"] = r.ComboBoxStaticBorder;
- combo.Resources["ComboBox.Static.Glyph"] = r.ComboBoxStaticGlyph;
- combo.Resources["ComboBox.MouseOver.Background"] = r.ComboBoxMouseOverBackground;
- combo.Resources["ComboBox.MouseOver.Border"] = r.ComboBoxMouseOverBorder;
- combo.Resources["ComboBox.MouseOver.Glyph"] = r.ComboBoxMouseOverGlyph;
- combo.Resources["ComboBox.Disabled.Background"] = r.ComboBoxDisabledBackground;
- combo.Resources["ComboBox.Disabled.Foreground"] = r.DisabledForeground;
- combo.Resources["ComboBox.Disabled.Border"] = r.ComboBoxDisabledBorder;
- combo.Resources["ComboBox.Disabled.Glyph"] = r.ComboBoxDisabledGlyph;
- }
- public ToolStripComboBox()
- {
- ComboBox = new InnerComboBox();
- SetItemControl(ComboBox);
- ComboBox.control.VerticalAlignment = VerticalAlignment.Stretch;
- ComboBox.control.Margin = new Thickness(0, 0, 4, 0);
- ComboBox.TextChanged += (sender, e) => OnTextChanged(e);
- ComboBox.SelectedIndexChanged += (sender, e) => OnSelectedIndexChanged(e);
- ComboBox.SelectedValueChanged += (sender, e) => OnSelectedValueChanged(e);
- AutoSize = false;
- }
- private class InnerComboBox : ComboBoxBase
- {
- public InnerComboBox()
- {
- SetComboBox(new CustomControls.ToolStripComboBox());
- }
- }
- }
- }
|