2 // ToolStripSeparator.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
31 using System.ComponentModel;
33 namespace System.Windows.Forms
35 public class ToolStripSeparator : ToolStripItem
37 private bool auto_tool_tip;
38 private ToolStripItemDisplayStyle display_style;
39 private bool double_click_enabled;
40 private ContentAlignment image_align;
41 private int image_index;
42 private ToolStripItemImageScaling image_scaling;
43 private ContentAlignment text_align;
44 private TextImageRelation text_image_relation;
45 private string tool_tip_text;
47 public ToolStripSeparator ()
49 this.ForeColor = SystemColors.ControlDark;
52 #region Public Properties
54 [EditorBrowsable (EditorBrowsableState.Never)]
55 public bool AutoToolTip {
56 get { return this.auto_tool_tip; }
57 set { this.auto_tool_tip = value; }
60 public override bool CanSelect { get { return false; } }
63 [EditorBrowsable (EditorBrowsableState.Never)]
64 public ToolStripItemDisplayStyle DisplayStyle {
65 get { return this.display_style; }
66 set { this.display_style = value; }
70 [EditorBrowsable (EditorBrowsableState.Never)]
71 public bool DoubleClickEnabled {
72 get { return this.double_click_enabled; }
73 set { this.double_click_enabled = value; }
77 [EditorBrowsable (EditorBrowsableState.Never)]
78 public override bool Enabled {
79 get { return base.Enabled; }
80 set { base.Enabled = value; }
84 [EditorBrowsable (EditorBrowsableState.Never)]
85 public override Font Font {
86 get { return base.Font; }
87 set { base.Font = value; }
91 [EditorBrowsable (EditorBrowsableState.Never)]
92 public override Image Image {
93 get { return base.Image; }
94 set { base.Image = value; }
98 [EditorBrowsable (EditorBrowsableState.Never)]
99 public ContentAlignment ImageAlign {
100 get { return this.image_align; }
102 if (!Enum.IsDefined (typeof (ContentAlignment), value))
103 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
105 this.image_align = value;
110 [EditorBrowsable (EditorBrowsableState.Never)]
111 public int ImageIndex {
112 get { return this.image_index; }
115 throw new ArgumentException ("ImageIndex cannot be less than -1");
117 this.image_index = value;
122 [EditorBrowsable (EditorBrowsableState.Never)]
123 public ToolStripItemImageScaling ImageScaling {
124 get { return this.image_scaling; }
125 set { this.image_scaling = value; }
129 [EditorBrowsable (EditorBrowsableState.Never)]
130 public override string Text {
131 get { return base.Text; }
132 set { base.Text = value; }
136 [EditorBrowsable (EditorBrowsableState.Never)]
137 public ContentAlignment TextAlign {
138 get { return this.text_align; }
140 if (!Enum.IsDefined (typeof (ContentAlignment), value))
141 throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
143 this.text_align = value;
148 [EditorBrowsable (EditorBrowsableState.Never)]
149 public TextImageRelation TextImageRelation {
150 get { return this.text_image_relation; }
151 set { this.text_image_relation = value; }
155 [EditorBrowsable (EditorBrowsableState.Never)]
156 public string ToolTipText {
157 get { return this.tool_tip_text; }
158 set { this.tool_tip_text = value; }
162 #region Protected Properties
163 protected internal override Padding DefaultMargin { get { return new Padding(); } }
164 protected override Size DefaultSize { get { return new Size(6, 6); } }
167 #region Public Methods
168 public override Size GetPreferredSize (Size constrainingSize)
170 return new Size(6, 6);
174 #region Protected Methods
175 protected override AccessibleObject CreateAccessibilityInstance ()
177 ToolStripItemAccessibleObject ao = new ToolStripItemAccessibleObject (this);
179 ao.default_action = "Press";
180 ao.role = AccessibleRole.Separator;
181 ao.state = AccessibleStates.None;
186 [EditorBrowsable (EditorBrowsableState.Never)]
187 protected override void OnFontChanged (EventArgs e)
189 base.OnFontChanged (e);
192 protected override void OnPaint (PaintEventArgs e)
196 if (this.Owner != null)
198 if (this.IsOnDropDown)
199 this.Owner.Renderer.DrawSeparator (new ToolStripSeparatorRenderEventArgs (e.Graphics, this, this.Owner.Orientation == Orientation.Horizontal ? false : true));
201 this.Owner.Renderer.DrawSeparator (new ToolStripSeparatorRenderEventArgs (e.Graphics, this, this.Owner.Orientation == Orientation.Horizontal ? true : false));
205 protected internal override void SetBounds (Rectangle bounds)
207 base.SetBounds (bounds);
211 #region Public Events
213 [EditorBrowsable (EditorBrowsableState.Never)]
214 public event EventHandler DisplayStyleChanged;
217 [EditorBrowsable (EditorBrowsableState.Never)]
218 public event EventHandler EnabledChanged;
221 [EditorBrowsable (EditorBrowsableState.Never)]
222 public event EventHandler TextChanged;