File size: 6,214 Bytes
b1b3bae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using FarsiLibrary.Win.Design;
namespace FarsiLibrary.Win
{
[Designer(typeof(FATabStripItemDesigner))]
[ToolboxItem(false)]
[DefaultProperty("Title")]
[DefaultEvent("Changed")]
public class FATabStripItem : Panel
{
#region Events
public event EventHandler Changed;
#endregion
#region Fields
//private DrawItemState drawState = DrawItemState.None;
private RectangleF stripRect = Rectangle.Empty;
private Image image = null;
private bool canClose = true;
private bool selected = false;
private bool visible = true;
private bool isDrawn = false;
private string title = string.Empty;
#endregion
#region Props
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new Size Size
{
get { return base.Size; }
set { base.Size = value; }
}
[DefaultValue(true)]
public new bool Visible
{
get { return visible; }
set
{
if (visible == value)
return;
visible = value;
OnChanged();
}
}
internal RectangleF StripRect
{
get { return stripRect; }
set { stripRect = value; }
}
[Browsable(false)]
[DefaultValue(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public bool IsDrawn
{
get { return isDrawn; }
set
{
if (isDrawn == value)
return;
isDrawn = value;
}
}
/// <summary>
/// Image of <see cref="FATabStripItem"/> which will be displayed
/// on menu items.
/// </summary>
[DefaultValue(null)]
public Image Image
{
get { return image; }
set { image = value; }
}
[DefaultValue(true)]
public bool CanClose
{
get { return canClose; }
set { canClose = value; }
}
[DefaultValue("Name")]
[Localizable(true)]
public string Title
{
get
{
return title;
}
set
{
if (title == value)
return;
title = value;
OnChanged();
}
}
/// <summary>
/// Gets and sets a value indicating if the page is selected.
/// </summary>
[DefaultValue(false)]
[Browsable(false)]
public bool Selected
{
get { return selected; }
set
{
if (selected == value)
return;
selected = value;
}
}
[Browsable(false)]
public string Caption
{
get { return Title; }
}
#endregion
#region Ctor
public FATabStripItem() : this(string.Empty, null)
{
}
public FATabStripItem(Control displayControl) : this(string.Empty, displayControl)
{
}
public FATabStripItem(string caption, Control displayControl)
{
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ContainerControl, true);
selected = false;
Visible = true;
UpdateText(caption, displayControl);
//Add to controls
if(displayControl != null)
Controls.Add(displayControl);
}
#endregion
#region IDisposable
/// <summary>
/// Handles proper disposition of the tab page control.
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if(disposing)
{
if(image != null)
image.Dispose();
}
}
#endregion
#region ShouldSerialize
public bool ShouldSerializeIsDrawn()
{
return false;
}
public bool ShouldSerializeDock()
{
return false;
}
public bool ShouldSerializeControls()
{
return Controls != null && Controls.Count > 0;
}
public bool ShouldSerializeVisible()
{
return true;
}
#endregion
#region Methods
private void UpdateText(string caption, Control displayControl)
{
if (displayControl != null && displayControl is ICaptionSupport)
{
ICaptionSupport capControl = displayControl as ICaptionSupport;
Title = capControl.Caption;
}
else if (caption.Length <= 0 && displayControl != null)
{
Title = displayControl.Text;
}
else if (caption != null)
{
Title = caption;
}
else
{
Title = string.Empty;
}
}
public void Assign(FATabStripItem item)
{
Visible = item.Visible;
Text = item.Text;
CanClose = item.CanClose;
Tag = item.Tag;
}
protected internal virtual void OnChanged()
{
if (Changed != null)
Changed(this, EventArgs.Empty);
}
/// <summary>
/// Return a string representation of page.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Caption;
}
#endregion
}
}
|