You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

253 lines
8.1 KiB

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())
{
}
/// <summary>
/// Create a strongly typed property called TrackBar - handy to prevent casting everywhere.
/// </summary>
public TrackBar TrackBar
{
get
{
return Control as TrackBar;
}
}
/// <summary>
/// Create the actual control, note this is static so it can be called from the
/// constructor.
///
/// </summary>
/// <returns></returns>
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; }
}
/// <summary>
/// Attach to events we want to re-wrap
/// </summary>
/// <param name="control"></param>
[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);
}
/// <summary>
/// Detach from events.
/// </summary>
/// <param name="control"></param>
protected override void OnUnsubscribeControlEvents(Control control)
{
base.OnUnsubscribeControlEvents(control);
TrackBar trackBar = control as TrackBar;
trackBar.ValueChanged -= new EventHandler(trackBar_ValueChanged);
}
/// <summary>
/// Routing for event
/// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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())
{
}
/// <summary>
/// Create a strongly typed property called TrackBar - handy to prevent casting everywhere.
/// </summary>
public NumericUpDown NumericUpDown
{
get
{
return Control as NumericUpDown;
}
}
/// <summary>
/// Create the actual control, note this is static so it can be called from the
/// constructor.
///
/// </summary>
/// <returns></returns>
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; }
}
/// <summary>
/// Attach to events we want to re-wrap
/// </summary>
/// <param name="control"></param>
[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);
}
/// <summary>
/// Detach from events.
/// </summary>
/// <param name="control"></param>
protected override void OnUnsubscribeControlEvents(Control control)
{
base.OnUnsubscribeControlEvents(control);
NumericUpDown t = control as NumericUpDown;
t.ValueChanged -= new EventHandler(updown_ValueChanged);
}
/// <summary>
/// Routing for event
/// TrackBar.ValueChanged -> ToolStripTrackBar.ValueChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
}