using System; using System.Drawing; using System.Windows.Forms; using System.ComponentModel; using System.Windows.Forms.Design; namespace UTIL { #region Компоненты меню [System.ComponentModel.DesignerCategory("code")] [ToolStripItemDesignerAvailability( ToolStripItemDesignerAvailability.ContextMenuStrip | ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.StatusStrip | ToolStripItemDesignerAvailability.ToolStrip)] public partial class ToolStripTrackBar : ToolStripControlHost { public ToolStripTrackBar() : base(CreateControlInstance()) { } /// /// Create a strongly typed property called TrackBar - handy to prevent casting everywhere. /// public TrackBar TrackBar { get { return Control as TrackBar; } } /// /// Create the actual control, note this is static so it can be called from the /// constructor. /// /// /// private static Control CreateControlInstance() { TrackBar t = new TrackBar(); t.AutoSize = false; // Add other initialization code here. return t; } [DefaultValue(0)] public int Value { get { return TrackBar.Value; } set { TrackBar.Value = value; } } /// /// Attach to events we want to re-wrap /// /// [DefaultValue(0)] public int Minimum { get { return TrackBar.Minimum; } set { TrackBar.Minimum = value; } } [DefaultValue(100)] public int Maximum { get { return TrackBar.Maximum; } set { TrackBar.Maximum = value; } } [DefaultValue(10)] public int TickFrequency { get { return TrackBar.TickFrequency; } set { TrackBar.TickFrequency = value; } } public TickStyle TickStyle { get { return TrackBar.TickStyle; } set { TrackBar.TickStyle = value; } } protected override void OnSubscribeControlEvents(Control control) { base.OnSubscribeControlEvents(control); TrackBar trackBar = control as TrackBar; trackBar.ValueChanged += new EventHandler(trackBar_ValueChanged); } /// /// Detach from events. /// /// protected override void OnUnsubscribeControlEvents(Control control) { base.OnUnsubscribeControlEvents(control); TrackBar trackBar = control as TrackBar; trackBar.ValueChanged -= new EventHandler(trackBar_ValueChanged); } /// /// Routing for event /// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged /// /// /// void trackBar_ValueChanged(object sender, EventArgs e) { // when the trackbar value changes, fire an event. if (this.ValueChanged != null) { ValueChanged(sender, e); } } // add an event that is subscribable from the designer. public event EventHandler ValueChanged; // set other defaults that are interesting protected override Size DefaultSize { get { return new Size(200, 16); } } } [System.ComponentModel.DesignerCategory("code")] [ToolStripItemDesignerAvailability( ToolStripItemDesignerAvailability.ContextMenuStrip | ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.StatusStrip | ToolStripItemDesignerAvailability.ToolStrip)] public partial class ToolStripNumericUpDown : ToolStripControlHost { public ToolStripNumericUpDown() : base(CreateControlInstance()) { } /// /// Create a strongly typed property called TrackBar - handy to prevent casting everywhere. /// public NumericUpDown NumericUpDown { get { return Control as NumericUpDown; } } /// /// Create the actual control, note this is static so it can be called from the /// constructor. /// /// /// private static Control CreateControlInstance() { NumericUpDown t = new NumericUpDown(); t.AutoSize = false; // Add other initialization code here. return t; } [DefaultValue(0)] public int Value { get { return (int)NumericUpDown.Value; } set { NumericUpDown.Value = value; } } /// /// Attach to events we want to re-wrap /// /// [DefaultValue(0)] public int Minimum { get { return (int)NumericUpDown.Minimum; } set { NumericUpDown.Minimum = value; } } [DefaultValue(100)] public int Maximum { get { return (int)NumericUpDown.Maximum; } set { NumericUpDown.Maximum = value; } } [DefaultValue(10)] public int Increment { get { return (int)NumericUpDown.Increment; } set { NumericUpDown.Increment = value; } } protected override void OnSubscribeControlEvents(Control control) { base.OnSubscribeControlEvents(control); NumericUpDown t = control as NumericUpDown; t.ValueChanged += new EventHandler(updown_ValueChanged); } /// /// Detach from events. /// /// protected override void OnUnsubscribeControlEvents(Control control) { base.OnUnsubscribeControlEvents(control); NumericUpDown t = control as NumericUpDown; t.ValueChanged -= new EventHandler(updown_ValueChanged); } /// /// Routing for event /// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged /// /// /// void updown_ValueChanged(object sender, EventArgs e) { // when the trackbar value changes, fire an event. if (this.ValueChanged != null) { ValueChanged(sender, e); } } // add an event that is subscribable from the designer. public event EventHandler ValueChanged; // set other defaults that are interesting protected override Size DefaultSize { get { return new Size(200, 16); } } } [System.ComponentModel.DesignerCategory("code")] [ToolStripItemDesignerAvailability( ToolStripItemDesignerAvailability.ContextMenuStrip | ToolStripItemDesignerAvailability.MenuStrip | ToolStripItemDesignerAvailability.StatusStrip | ToolStripItemDesignerAvailability.ToolStrip)] public partial class ToolStripLabel : ToolStripControlHost { public ToolStripLabel() : base(CreateControlInstance()) { } public Label Label { get { return Control as Label; } } private static Control CreateControlInstance() { Label t = new Label(); t.AutoSize = false; t.Height = 15; // t.Width = 120; t.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // Add other initialization code here. return t; } } #endregion }