DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 824 B

View File

@@ -0,0 +1,667 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using DevComponents.DotNetBar.Rendering;
using System.Reflection;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the class for the BaseItem non-popup based control host.
/// </summary>
[ToolboxItem(false)]
public abstract class BaseItemControl : Control
{
#region Private Variables
private BaseItem m_Item = null;
private ElementStyle m_BackgroundStyle = null;
private ColorScheme m_ColorScheme = null;
private bool m_DesignModeInternal = false;
private bool m_AntiAlias = true;
#endregion
#region Constructor Dispose
/// <summary>
/// Creates new instance of the object.
/// </summary>
public BaseItemControl()
{
if (!ColorFunctions.ColorsLoaded)
{
NativeFunctions.RefreshSettings();
NativeFunctions.OnDisplayChange();
ColorFunctions.LoadColors();
}
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.StandardDoubleClick, true);
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
m_ColorScheme = new ColorScheme(eDotNetBarStyle.Office2007);
m_BackgroundStyle = new ElementStyle();
m_BackgroundStyle.SetColorScheme(m_ColorScheme);
m_BackgroundStyle.StyleChanged += new EventHandler(this.VisualPropertyChanged);
}
protected override void Dispose(bool disposing)
{
if (disposing && m_Item != null)
m_Item.Dispose();
base.Dispose(disposing);
}
#endregion
#region Internal Implementation
protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
{
if (Dpi.RecordScalePerControl)
Dpi.SetScaling(factor);
if (m_Item != null)
{
m_Item.NotifyScaleItem(factor);
RecalcLayout();
}
base.ScaleControl(factor, specified);
}
internal bool IsValidationCancelled
{
get
{
PropertyInfo pi=this.GetType().GetProperty("ValidationCancelled", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (pi != null)
return (bool)pi.GetValue(this, null);
return false;
}
}
#if FRAMEWORK20
protected override void OnBindingContextChanged(EventArgs e)
{
base.OnBindingContextChanged(e);
if (m_Item != null)
m_Item.UpdateBindings();
}
#endif
protected bool GetDesignMode()
{
if (!m_DesignModeInternal)
return this.DesignMode;
return m_DesignModeInternal;
}
protected virtual ElementStyle GetBackgroundStyle()
{
return m_BackgroundStyle;
}
internal void SetDesignMode(bool mode)
{
m_DesignModeInternal = mode;
if(m_Item!=null)
m_Item.SetDesignMode(mode);
}
/// <summary>
/// Gets or sets the instance of BaseItem object hosted by this control.
/// </summary>
protected virtual BaseItem HostItem
{
get { return m_Item; }
set
{
m_Item = value;
if (m_Item != null)
{
m_Item.Displayed = true;
m_Item.ContainerControl = this;
}
}
}
/// <summary>
/// Returns the color scheme used by control. Color scheme for Office2007 style will be retrieved from the current renderer instead of
/// local color scheme referenced by ColorScheme property.
/// </summary>
/// <returns>An instance of ColorScheme object.</returns>
protected virtual ColorScheme GetColorScheme()
{
if (m_Item != null && BarFunctions.IsOffice2007Style(m_Item.EffectiveStyle))
{
BaseRenderer r = GetRenderer();
if (r is Office2007Renderer)
return ((Office2007Renderer)r).ColorTable.LegacyColors;
}
return m_ColorScheme;
}
private bool _CallBasePaintBackground = true;
/// <summary>
/// Gets or sets whether during painting OnPaintBackground on base control is called when BackColor=Transparent.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool CallBasePaintBackground
{
get { return _CallBasePaintBackground; }
set
{
_CallBasePaintBackground = value;
}
}
internal void InternalPaint(PaintEventArgs e)
{
OnPaint(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if ((this.BackColor.IsEmpty || this.BackColor == Color.Transparent) && _CallBasePaintBackground)
{
base.OnPaintBackground(e);
}
if (m_BackgroundStyle != null)
m_BackgroundStyle.SetColorScheme(this.GetColorScheme());
PaintBackground(e);
PaintControl(e);
if (this.Focused && /*this.ShowFocusCues &&*/ this.FocusCuesEnabled)
{
PaintFocusCues(e);
}
base.OnPaint(e);
}
private bool _FocusCuesEnabled = true;
/// <summary>
/// Gets or sets whether control displays focus cues when focused.
/// </summary>
[DefaultValue(true), Category("Behavior"), Description("Indicates whether control displays focus cues when focused.")]
public virtual bool FocusCuesEnabled
{
get { return _FocusCuesEnabled; }
set
{
_FocusCuesEnabled = value;
if (this.Focused) this.Invalidate();
}
}
/// <summary>
/// Paints the control focus cues.
/// </summary>
/// <param name="e">Paint event information.</param>
protected virtual void PaintFocusCues(PaintEventArgs e)
{
ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle);
}
protected virtual void PaintBackground(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle r = this.ClientRectangle;
ElementStyle style = this.GetBackgroundStyle();
if (!this.BackColor.IsEmpty && this.BackColor != Color.Transparent)
{
DisplayHelp.FillRectangle(g, r, this.BackColor);
}
if (this.BackgroundImage != null)
base.OnPaintBackground(e);
if (style.Custom)
{
SmoothingMode sm = g.SmoothingMode;
if (m_AntiAlias)
g.SmoothingMode = SmoothingMode.HighQuality;
ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(style, e.Graphics, r);
ElementStyleDisplay.Paint(displayInfo);
if (m_AntiAlias)
g.SmoothingMode = sm;
}
}
protected virtual void PaintControl(PaintEventArgs e)
{
SmoothingMode sm = e.Graphics.SmoothingMode;
TextRenderingHint th = e.Graphics.TextRenderingHint;
Graphics g = e.Graphics;
if (m_AntiAlias)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
}
ItemPaintArgs pa = GetItemPaintArgs(g);
pa.ClipRectangle = e.ClipRectangle;
if (m_Item != null) m_Item.Paint(pa);
if (m_AntiAlias)
{
g.SmoothingMode = sm;
g.TextRenderingHint = th;
}
}
/// <summary>
/// Creates the Graphics object for the control.
/// </summary>
/// <returns>The Graphics object for the control.</returns>
public new Graphics CreateGraphics()
{
Graphics g = base.CreateGraphics();
if (m_AntiAlias)
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
#if FRAMEWORK20
if (!SystemInformation.IsFontSmoothingEnabled)
#endif
g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
}
return g;
}
protected virtual ItemPaintArgs GetItemPaintArgs(Graphics g)
{
ItemPaintArgs pa = new ItemPaintArgs(this as IOwner, this, g, GetColorScheme());
pa.Renderer = this.GetRenderer();
pa.DesignerSelection = false;
pa.GlassEnabled = !this.DesignMode && WinApi.IsGlassEnabled;
return pa;
}
private Rendering.BaseRenderer m_DefaultRenderer = null;
private Rendering.BaseRenderer m_Renderer = null;
private eRenderMode m_RenderMode = eRenderMode.Global;
/// <summary>
/// Returns the renderer control will be rendered with.
/// </summary>
/// <returns>The current renderer.</returns>
public virtual Rendering.BaseRenderer GetRenderer()
{
if (m_RenderMode == eRenderMode.Global && Rendering.GlobalManager.Renderer != null)
return Rendering.GlobalManager.Renderer;
else if (m_RenderMode == eRenderMode.Custom && m_Renderer != null)
return m_Renderer;
if (m_DefaultRenderer == null)
m_DefaultRenderer = new Rendering.Office2007Renderer();
return m_Renderer;
}
/// <summary>
/// Gets or sets the redering mode used by control. Default value is eRenderMode.Global which means that static GlobalManager.Renderer is used. If set to Custom then Renderer property must
/// also be set to the custom renderer that will be used.
/// </summary>
[Browsable(false), DefaultValue(eRenderMode.Global)]
public eRenderMode RenderMode
{
get { return m_RenderMode; }
set
{
if (m_RenderMode != value)
{
m_RenderMode = value;
this.Invalidate(true);
}
}
}
/// <summary>
/// Gets or sets the custom renderer used by the items on this control. RenderMode property must also be set to eRenderMode.Custom in order renderer
/// specified here to be used.
/// </summary>
[Browsable(false), DefaultValue(null)]
public DevComponents.DotNetBar.Rendering.BaseRenderer Renderer
{
get
{
return m_Renderer;
}
set { m_Renderer = value; }
}
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Style"), Description("Gets or sets bar background style."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return m_BackgroundStyle; }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
m_BackgroundStyle.StyleChanged -= new EventHandler(this.VisualPropertyChanged);
m_BackgroundStyle = new ElementStyle();
m_BackgroundStyle.StyleChanged += new EventHandler(this.VisualPropertyChanged);
OnBackgroundStyleChanged();
this.Invalidate();
}
protected virtual void OnBackgroundStyleChanged()
{
}
private void VisualPropertyChanged(object sender, EventArgs e)
{
OnVisualPropertyChanged();
}
/// <summary>
/// Called when visual property of the control has changed so the control can be updated.
/// </summary>
protected virtual void OnVisualPropertyChanged()
{
if (this.GetDesignMode() ||
this.Parent != null && this.Parent.Site != null && this.Parent.Site.DesignMode)
{
this.RecalcLayout();
}
}
/// <summary>
/// Gets or sets Bar Color Scheme.
/// </summary>
[Browsable(false), DevCoBrowsable(false), Category("Appearance"), Description("Gets or sets Bar Color Scheme."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ColorScheme ColorScheme
{
get { return m_ColorScheme; }
set
{
if (value == null)
throw new ArgumentException("NULL is not a valid value for this property.");
m_ColorScheme = value;
if (this.Visible)
this.Refresh();
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeColorScheme()
{
return m_ColorScheme.SchemeChanged;
}
/// <summary>
/// Gets or sets whether anti-alias smoothing is used while painting. Default value is false.
/// </summary>
[DefaultValue(true), Browsable(true), Category("Appearance"), Description("Gets or sets whether anti-aliasing is used while painting.")]
public bool AntiAlias
{
get { return m_AntiAlias; }
set
{
if (m_AntiAlias != value)
{
m_AntiAlias = value;
this.Invalidate();
}
}
}
protected override void OnParentChanged(EventArgs e)
{
base.OnParentChanged(e);
//if (this.Parent != null && (this.Images != null || this.ImagesLarge != null || this.ImagesMedium != null))
//{
// foreach (BaseItem panel in m_BaseItemContainer.SubItems)
// {
// foreach (BaseItem item in panel.SubItems)
// {
// if (item is ImageItem)
// ((ImageItem)item).OnImageChanged();
// }
// }
//}
if (this.DesignMode && m_Item!=null)
m_Item.SetDesignMode(this.DesignMode);
}
/// <summary>
/// Forces the button to perform internal layout.
/// </summary>
public virtual void RecalcLayout()
{
if (m_Item == null) return;
Rectangle r = GetItemBounds();
m_Item.Bounds = r;
this.RecalcSize();
m_Item.Bounds = r;
this.Invalidate();
}
/// <summary>
/// Recalculates the size of the internal item.
/// </summary>
protected virtual void RecalcSize()
{
m_Item.RecalcSize();
}
protected virtual Rectangle GetItemBounds()
{
Rectangle r = this.ClientRectangle;
r.X += ElementStyleLayout.LeftWhiteSpace(this.BackgroundStyle);
r.Width -= ElementStyleLayout.HorizontalStyleWhiteSpace(this.BackgroundStyle);
r.Y += ElementStyleLayout.TopWhiteSpace(this.BackgroundStyle);
r.Height -= ElementStyleLayout.VerticalStyleWhiteSpace(this.BackgroundStyle);
return r;
}
protected override void OnResize(EventArgs e)
{
RecalcLayout();
base.OnResize(e);
}
protected override void OnTextChanged(EventArgs e)
{
m_Item.Text = this.Text;
this.RecalcLayout();
base.OnTextChanged(e);
}
protected override void OnFontChanged(EventArgs e)
{
base.OnFontChanged(e);
BarUtilities.InvalidateFontChange(m_Item);
this.RecalcLayout();
}
protected override void OnEnabledChanged(EventArgs e)
{
m_Item.Enabled = this.Enabled;
base.OnEnabledChanged(e);
}
private bool m_MouseFocus = false;
protected override void OnGotFocus(EventArgs e)
{
if (!m_MouseFocus)
m_Item.OnGotFocus();
m_MouseFocus = false;
base.OnGotFocus(e);
}
protected override void OnLostFocus(EventArgs e)
{
m_Item.OnLostFocus();
base.OnLostFocus(e);
}
protected override void OnMouseEnter(EventArgs e)
{
m_Item.InternalMouseEnter();
base.OnMouseEnter(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
m_Item.InternalMouseMove(e);
base.OnMouseMove(e);
}
protected override void OnMouseLeave(EventArgs e)
{
m_Item.InternalMouseLeave();
base.OnMouseLeave(e);
}
protected override void OnMouseHover(EventArgs e)
{
m_Item.InternalMouseHover();
base.OnMouseHover(e);
}
protected virtual MouseButtons MouseDownFocusButtons
{
get { return MouseButtons.Left; }
}
protected override void OnMouseDown(MouseEventArgs e)
{
if ((e.Button & MouseDownFocusButtons) != 0)
{
if (!this.Focused && this.GetStyle(ControlStyles.Selectable))
{
m_MouseFocus = true;
this.Select();
}
}
m_Item.InternalMouseDown(e);
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
m_Item.InternalMouseUp(e);
base.OnMouseUp(e);
}
protected override void OnClick(EventArgs e)
{
m_Item.InternalClick(Control.MouseButtons, this.PointToClient(Control.MousePosition));
base.OnClick(e);
}
protected override void OnDoubleClick(EventArgs e)
{
m_Item.InternalDoubleClick(Control.MouseButtons, this.PointToClient(Control.MousePosition));
base.OnDoubleClick(e);
}
protected override void OnKeyDown(KeyEventArgs e)
{
m_Item.InternalKeyDown(e);
base.OnKeyDown(e);
}
/// <summary>
/// Gets/Sets the visual style for the control.
/// </summary>
[Browsable(true), Category("Appearance"), Description("Specifies the visual style of the control."), DefaultValue(eDotNetBarStyle.Office2007)]
public virtual eDotNetBarStyle Style
{
get
{
return m_Item.Style;
}
set
{
m_Item.Style = value;
if(!BarFunctions.IsOffice2007Style(value))
this.GetColorScheme().Style = value;
this.RecalcLayout();
}
}
protected override bool ProcessMnemonic(char charCode)
{
if (IsMnemonic(charCode, m_Item.Text))
{
if (ProcessAccelerator())
return true;
}
return base.ProcessMnemonic(charCode);
}
protected virtual bool ProcessAccelerator()
{
m_Item.RaiseClick(eEventSource.Keyboard);
return true;
}
#endregion
#region Layout Support
private int m_UpdateSuspendCount = 0;
/// <summary>
/// Indicates to control that all further update operations should not result in layout and refresh of control content.
/// Use this method to optimize the addition of new items to the control. This method supports nested calls meaning
/// that multiple calls are allowed but they must be ended with appropriate number of EndUpdate calls.
/// IsUpdateSuspended property returns whether update is suspended.
/// </summary>
public void BeginUpdate()
{
m_UpdateSuspendCount++;
}
/// <summary>
/// Indicates that update operation is complete and that control should perform layout and refresh to show changes. See BeginUpdate
/// for more details.
/// </summary>
public void EndUpdate()
{
EndUpdate(true);
}
/// <summary>
/// Indicates that update operation is complete and that control should perform layout and refresh to show changes. See BeginUpdate
/// for more details.
/// </summary>
public void EndUpdate(bool callRecalcLayout)
{
if (m_UpdateSuspendCount > 0)
{
m_UpdateSuspendCount--;
if (m_UpdateSuspendCount == 0 && callRecalcLayout)
this.RecalcLayout();
}
}
/// <summary>
/// Gets whether control layout is suspended becouse of the call to BeginUpdate method.
/// </summary>
[Browsable(false)]
public bool IsUpdateSuspended
{
get { return m_UpdateSuspendCount > 0; }
}
#endregion
}
}

View File

@@ -0,0 +1,671 @@
using System.ComponentModel;
using System.Globalization;
using System.Drawing;
using System.Runtime.InteropServices;
using DevComponents.DotNetBar;
using System.Windows.Forms;
using System;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents the bound data navigator in current DotNetBar style.
/// </summary>
[DefaultEvent("RefreshItems"), Description("DotNetBar Binding Navigator Control"), ClassInterface(ClassInterfaceType.AutoDispatch), DefaultProperty("BindingSource")]
[Designer("DevComponents.DotNetBar.Design.BindingNavigatorExDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
[ToolboxBitmap(typeof(BindingNavigatorEx), "Controls.BindingNavigatorEx.ico"), ToolboxItem(true)]
public class BindingNavigatorEx : Bar, ISupportInitialize
{
#region Private Variables
private ButtonItem _AddNewButton;
private bool _AddNewItemUserEnabled;
private BindingSource _BindingSource;
private LabelItem _CountLabel;
private string _CountLabelFormat;
private ButtonItem _DeleteButton;
private bool _DeleteButtonUserEnabled;
private bool _Initializing;
private ButtonItem _MoveFirstButton;
private ButtonItem _MoveLastButton;
private ButtonItem _MoveNextButton;
private ButtonItem _MovePreviousButton;
private TextBoxItem _PositionTextBox;
#endregion
#region Constructor
/// <summary>
/// Creates new instance of BindingNavigatorEx
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public BindingNavigatorEx()
: this(false)
{
}
/// <summary>
/// Creates new instance of BindingNavigatorEx
/// </summary>
public BindingNavigatorEx(bool addStandardItems)
{
_CountLabelFormat = "of {0}";
_AddNewItemUserEnabled = true;
_DeleteButtonUserEnabled = true;
if (addStandardItems)
{
this.AddDefaultItems();
}
}
/// <summary>
/// Creates new instance of BindingNavigatorEx
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public BindingNavigatorEx(IContainer container)
: this(false)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
container.Add(this);
}
/// <summary>
/// Creates new instance of BindingNavigatorEx
/// </summary>
public BindingNavigatorEx(BindingSource bindingSource)
: this(true)
{
this.BindingSource = bindingSource;
}
#endregion
#region Internal Implementation
private void AcceptNewPosition()
{
if (_PositionTextBox != null && _BindingSource != null)
{
int position = this._BindingSource.Position;
try
{
position = Convert.ToInt32(this._PositionTextBox.Text, CultureInfo.CurrentCulture) - 1;
}
catch (FormatException)
{
}
catch (OverflowException)
{
}
if (position != this._BindingSource.Position)
{
this._BindingSource.Position = position;
}
this.RefreshStateInternal();
}
}
/// <summary>
/// Adds default items that make up the binding navigation control.
/// </summary>
public virtual void AddDefaultItems()
{
this.MoveFirstButton = new ButtonItem();
this.MovePreviousButton = new ButtonItem();
this.MoveNextButton = new ButtonItem();
this.MoveLastButton = new ButtonItem();
this.PositionTextBox = new TextBoxItem();
this.CountLabel = new LabelItem();
this.AddNewRecordButton = new ButtonItem();
this.DeleteButton = new ButtonItem();
char ch = (string.IsNullOrEmpty(base.Name) || char.IsLower(base.Name[0])) ? 'b' : 'B';
this.MoveFirstButton.Name = ch + "indingNavigatorMoveFirstItem";
this.MovePreviousButton.Name = ch + "indingNavigatorMovePreviousItem";
this.MoveNextButton.Name = ch + "indingNavigatorMoveNextItem";
this.MoveLastButton.Name = ch + "indingNavigatorMoveLastItem";
this.PositionTextBox.Name = ch + "indingNavigatorPositionItem";
this.CountLabel.Name = ch + "indingNavigatorCountItem";
this.AddNewRecordButton.Name = ch + "indingNavigatorAddNewItem";
this.DeleteButton.Name = ch + "indingNavigatorDeleteItem";
this.MoveFirstButton.Text = "Move first";
this.MovePreviousButton.Text = "Move previous";
this.MoveNextButton.Text = "Move next";
this.MoveLastButton.Text = "Move last";
this.AddNewRecordButton.Text = "Add new";
this.DeleteButton.Text = "Delete";
this.PositionTextBox.AccessibleName = "Position";
_PositionTextBox.BeginGroup = true;
_MoveNextButton.BeginGroup = true;
_MoveFirstButton.Image = BarFunctions.LoadBitmap("SystemImages.FirstRecord.png");
_MovePreviousButton.Image = BarFunctions.LoadBitmap("SystemImages.PreviousRecord.png");
_MoveNextButton.Image = BarFunctions.LoadBitmap("SystemImages.NextRecord.png"); ;
_MoveLastButton.Image = BarFunctions.LoadBitmap("SystemImages.LastRecord.png"); ;
_AddNewButton.Image = BarFunctions.LoadBitmap("SystemImages.NewRecord.png"); ;
_DeleteButton.Image = BarFunctions.LoadBitmap("SystemImages.Delete.png"); ;
_PositionTextBox.TextBoxWidth = 54;
this.Items.AddRange(new BaseItem[] { this.MoveFirstButton, this.MovePreviousButton, this.PositionTextBox, this.CountLabel, this.MoveNextButton, this.MoveLastButton, this.AddNewRecordButton, this.DeleteButton });
}
private void CancelNewPosition()
{
this.RefreshStateInternal();
}
private bool _IsDisposing = false;
protected override void Dispose(bool disposing)
{
if (disposing)
{
_IsDisposing = true;
try
{
this.BindingSource = null;
}
finally
{
_IsDisposing = false;
}
}
base.Dispose(disposing);
}
private void OnAddNew(object sender, EventArgs e)
{
if (this.Validate() && _BindingSource != null)
{
_BindingSource.EndEdit();
_BindingSource.AddNew();
RefreshStateInternal();
}
}
private void OnAddNewItemEnabledChanged(object sender, EventArgs e)
{
if (AddNewRecordButton != null)
{
_AddNewItemUserEnabled = _AddNewButton.Enabled;
}
}
private void OnBindingSourceListChanged(object sender, ListChangedEventArgs e)
{
RefreshStateInternal();
}
private void OnBindingSourceStateChanged(object sender, EventArgs e)
{
RefreshStateInternal();
}
private void OnDelete(object sender, EventArgs e)
{
if (this.Validate() && _BindingSource != null)
{
_BindingSource.RemoveCurrent();
RefreshStateInternal();
}
}
private void OnDeleteItemEnabledChanged(object sender, EventArgs e)
{
if (DeleteButton != null)
{
_DeleteButtonUserEnabled = _DeleteButton.Enabled;
}
}
private void OnMoveFirst(object sender, EventArgs e)
{
if (Validate() && _BindingSource != null)
{
_BindingSource.MoveFirst();
RefreshStateInternal();
}
}
private void OnMoveLast(object sender, EventArgs e)
{
if (Validate() && _BindingSource != null)
{
_BindingSource.MoveLast();
RefreshStateInternal();
}
}
private void OnMoveNext(object sender, EventArgs e)
{
if (Validate() && this._BindingSource != null)
{
_BindingSource.MoveNext();
RefreshStateInternal();
}
}
private void OnMovePrevious(object sender, EventArgs e)
{
if (Validate() && _BindingSource != null)
{
_BindingSource.MovePrevious();
RefreshStateInternal();
}
}
private void OnPositionKey(object sender, KeyEventArgs e)
{
Keys keyCode = e.KeyCode;
if (keyCode != Keys.Return)
{
if (keyCode != Keys.Escape)
{
return;
}
}
else
{
AcceptNewPosition();
return;
}
CancelNewPosition();
}
private void OnPositionLostFocus(object sender, EventArgs e)
{
AcceptNewPosition();
}
protected virtual void OnRefreshState()
{
RefreshState();
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void RefreshState()
{
int count;
int currentPosition;
bool allowNew;
bool allowRemove;
if (_BindingSource == null)
{
count = 0;
currentPosition = 0;
allowNew = false;
allowRemove = false;
}
else if (_BindingSource.Position == -1)
{
count = -1;
currentPosition = -1;
allowNew = true;
allowRemove = false;
}
else
{
count = _BindingSource.Count;
currentPosition = _BindingSource.Position + 1;
allowNew = _BindingSource.AllowNew;
allowRemove = _BindingSource.AllowRemove;
}
if (!base.DesignMode)
{
if (MoveFirstButton != null)
{
_MoveFirstButton.Enabled = currentPosition > 1;
}
if (MovePreviousButton != null)
{
_MovePreviousButton.Enabled = currentPosition > 1;
}
if (MoveNextButton != null)
{
_MoveNextButton.Enabled = currentPosition < count;
}
if (MoveLastButton != null)
{
_MoveLastButton.Enabled = currentPosition < count;
}
if (AddNewRecordButton != null)
{
EventHandler handler = this.OnAddNewItemEnabledChanged;
_AddNewButton.EnabledChanged -= handler;
_AddNewButton.Enabled = _AddNewItemUserEnabled && allowNew;
_AddNewButton.EnabledChanged += handler;
}
if (DeleteButton != null)
{
EventHandler handler2 = OnDeleteItemEnabledChanged;
_DeleteButton.EnabledChanged -= handler2;
_DeleteButton.Enabled = (this._DeleteButtonUserEnabled && allowRemove) && (count > 0);
_DeleteButton.EnabledChanged += handler2;
}
if (PositionTextBox != null)
{
_PositionTextBox.Enabled = (currentPosition > 0) && (count > 0);
}
if (CountLabel != null)
{
_CountLabel.Enabled = count > 0;
}
}
if (_PositionTextBox != null)
{
_PositionTextBox.Text = currentPosition.ToString(CultureInfo.CurrentCulture);
}
if (_CountLabel != null)
{
_CountLabel.Text = base.DesignMode ? CountLabelFormat : string.Format(CultureInfo.CurrentCulture, CountLabelFormat, new object[] { count });
}
}
private void RefreshStateInternal()
{
if (!_Initializing && !_IsDisposing)
OnRefreshState();
}
public bool Validate()
{
bool flag = false;
System.Reflection.MethodInfo mi = ((Control)this).GetType().GetMethod("ValidateActiveControl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
if (mi != null)
{
return (bool)mi.Invoke(this, new object[] { flag });
}
return true;
}
private void WireUpBindingSource(ref BindingSource oldBindingSource, BindingSource newBindingSource)
{
if (oldBindingSource != newBindingSource)
{
if (oldBindingSource != null)
{
oldBindingSource.PositionChanged -= OnBindingSourceStateChanged;
oldBindingSource.CurrentChanged -= OnBindingSourceStateChanged;
oldBindingSource.CurrentItemChanged -= OnBindingSourceStateChanged;
oldBindingSource.DataSourceChanged -= OnBindingSourceStateChanged;
oldBindingSource.DataMemberChanged -= OnBindingSourceStateChanged;
oldBindingSource.ListChanged -= OnBindingSourceListChanged;
}
if (newBindingSource != null)
{
newBindingSource.PositionChanged += OnBindingSourceStateChanged;
newBindingSource.CurrentChanged += OnBindingSourceStateChanged;
newBindingSource.CurrentItemChanged += OnBindingSourceStateChanged;
newBindingSource.DataSourceChanged += OnBindingSourceStateChanged;
newBindingSource.DataMemberChanged += OnBindingSourceStateChanged;
newBindingSource.ListChanged += OnBindingSourceListChanged;
}
oldBindingSource = newBindingSource;
this.RefreshStateInternal();
}
}
private void WireUpButton(ref ButtonItem oldButton, ButtonItem newButton, EventHandler clickHandler)
{
if (oldButton != newButton)
{
if (oldButton != null)
{
oldButton.Click -= clickHandler;
}
if (newButton != null)
{
newButton.Click += clickHandler;
}
oldButton = newButton;
this.RefreshStateInternal();
}
}
private void WireUpLabel(ref LabelItem oldLabel, LabelItem newLabel)
{
if (oldLabel != newLabel)
{
oldLabel = newLabel;
this.RefreshStateInternal();
}
}
private void WireUpTextBox(ref TextBoxItem oldTextBox, TextBoxItem newTextBox, KeyEventHandler keyUpHandler, EventHandler lostFocusHandler)
{
if (oldTextBox != newTextBox)
{
if (oldTextBox != null)
{
oldTextBox.KeyUp -= keyUpHandler;
oldTextBox.LostFocus -= lostFocusHandler;
}
if (newTextBox != null)
{
newTextBox.KeyUp += keyUpHandler;
newTextBox.LostFocus += lostFocusHandler;
}
oldTextBox = newTextBox;
this.RefreshStateInternal();
}
}
/// <summary>
/// Gets or sets the reference to Add New record button.
/// </summary>
[DefaultValue(null), Category("Items"), TypeConverter(typeof(ReferenceConverter)), Description("BindingNavigatorAddNewItemPropDescr")]
public ButtonItem AddNewRecordButton
{
get
{
if (_AddNewButton != null && _AddNewButton.IsDisposed)
{
_AddNewButton = null;
}
return _AddNewButton;
}
set
{
if ((_AddNewButton != value) && (value != null))
{
value.EnabledChanged += OnAddNewItemEnabledChanged;
_AddNewItemUserEnabled = value.Enabled;
}
WireUpButton(ref _AddNewButton, value, OnAddNew);
}
}
/// <summary>
/// Gets or sets the binding source for the navigator.
/// </summary>
[Category("Data"), Description("Gets or sets the binding source for the navigator."), DefaultValue((string)null), TypeConverter(typeof(ReferenceConverter))]
public BindingSource BindingSource
{
get
{
return _BindingSource;
}
set
{
WireUpBindingSource(ref _BindingSource, value);
}
}
/// <summary>
/// Gets or sets the label which represents the items count.
/// </summary>
[TypeConverter(typeof(ReferenceConverter)), Category("Items"), Description("Indicates label which represents the items count.")]
public LabelItem CountLabel
{
get
{
if (_CountLabel != null && _CountLabel.IsDisposed)
{
_CountLabel = null;
}
return _CountLabel;
}
set
{
this.WireUpLabel(ref _CountLabel, value);
}
}
/// <summary>
/// Indicates the format string for the label which displays the number of items bound.
/// </summary>
[Description("Indicates the format string for the label which displays the number of items bound."), Category("Appearance")]
public string CountLabelFormat
{
get
{
return _CountLabelFormat;
}
set
{
if (_CountLabelFormat != value)
{
_CountLabelFormat = value;
RefreshStateInternal();
}
}
}
/// <summary>
/// Gets or sets the item which deletes current record.
/// </summary>
[DefaultValue(null), Description("Indicates item which deletes current record."), TypeConverter(typeof(ReferenceConverter)), Category("Items")]
public ButtonItem DeleteButton
{
get
{
if ((this._DeleteButton != null) && this._DeleteButton.IsDisposed)
{
_DeleteButton = null;
}
return _DeleteButton;
}
set
{
if ((this._DeleteButton != value) && (value != null))
{
value.EnabledChanged += new EventHandler(this.OnDeleteItemEnabledChanged);
_DeleteButtonUserEnabled = value.Enabled;
}
this.WireUpButton(ref _DeleteButton, value, new EventHandler(this.OnDelete));
}
}
/// <summary>
/// Gets or sets the item which moves to first record.
/// </summary>
[DefaultValue(null), TypeConverter(typeof(ReferenceConverter)), Category("Items"), Description("Indicates item which moves to first record.")]
public ButtonItem MoveFirstButton
{
get
{
if (_MoveFirstButton != null && _MoveFirstButton.IsDisposed)
{
_MoveFirstButton = null;
}
return _MoveFirstButton;
}
set
{
WireUpButton(ref _MoveFirstButton, value, this.OnMoveFirst);
}
}
/// <summary>
/// Gets or sets the item which moves to last record.
/// </summary>
[DefaultValue(null), Category("Items"), Description("Indicates item which moves to last record."), TypeConverter(typeof(ReferenceConverter))]
public ButtonItem MoveLastButton
{
get
{
if ((_MoveLastButton != null) && _MoveLastButton.IsDisposed)
{
_MoveLastButton = null;
}
return _MoveLastButton;
}
set
{
this.WireUpButton(ref _MoveLastButton, value, OnMoveLast);
}
}
/// <summary>
/// Gets or sets the item which moves to next record.
/// </summary>
[DefaultValue(null), TypeConverter(typeof(ReferenceConverter)), Category("Items"), Description("Indicates item which moves to next record")]
public ButtonItem MoveNextButton
{
get
{
if (_MoveNextButton != null && _MoveNextButton.IsDisposed)
{
_MoveNextButton = null;
}
return _MoveNextButton;
}
set
{
this.WireUpButton(ref _MoveNextButton, value, new EventHandler(this.OnMoveNext));
}
}
/// <summary>
/// Gets or sets the item which moves to previous record.
/// </summary>
[DefaultValue(null), Description("Indicates item which moves to previous record"), TypeConverter(typeof(ReferenceConverter)), Category("Items")]
public ButtonItem MovePreviousButton
{
get
{
if (_MovePreviousButton != null && this._MovePreviousButton.IsDisposed)
{
_MovePreviousButton = null;
}
return _MovePreviousButton;
}
set
{
this.WireUpButton(ref _MovePreviousButton, value, OnMovePrevious);
}
}
/// <summary>
/// Gets or sets the text-box which shows current position.
/// </summary>
[DefaultValue(null), Category("Items"), Description("Indicates text-box which shows current position."), TypeConverter(typeof(ReferenceConverter))]
public TextBoxItem PositionTextBox
{
get
{
if (_PositionTextBox != null && _PositionTextBox.IsDisposed)
{
_PositionTextBox = null;
}
return _PositionTextBox;
}
set
{
this.WireUpTextBox(ref _PositionTextBox, value, OnPositionKey, OnPositionLostFocus);
}
}
#endregion
#region ISupportInitialize Members
void ISupportInitialize.BeginInit()
{
_Initializing = true;
}
void ISupportInitialize.EndInit()
{
_Initializing = false;
this.RefreshStateInternal();
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,786 @@
using System;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents the Check Box control with extended styles.
/// </summary>
[ToolboxBitmap(typeof(CheckBoxX), "Controls.CheckBoxX.ico"), ToolboxItem(true), DefaultEvent("CheckedChanged"), System.Runtime.InteropServices.ComVisible(false), Designer("DevComponents.DotNetBar.Design.CheckBoxXDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class CheckBoxX : BaseItemControl, ICommandSource
{
#region Private Variables
private const string DefaultCheckValueUnchecked = "N";
private const string DefaultCheckValueChecked = "Y";
private const object DefaultCheckValueIndeterminate = null;
private CheckBoxItem m_CheckBox = null;
private object m_CheckValue = DefaultCheckValueUnchecked;
private object m_CheckValueUnchecked = DefaultCheckValueUnchecked;
private object m_CheckValueChecked = DefaultCheckValueChecked;
private object m_CheckValueIndeterminate = DefaultCheckValueIndeterminate;
private bool m_ConsiderEmptyStringAsNull = true;
#endregion
#region Events
/// <summary>
/// Occurs before Checked property is changed and allows you to cancel the change.
/// </summary>
public event CheckBoxXChangeEventHandler CheckedChanging;
/// <summary>
/// Occurs after Checked property is changed with extended information.
/// </summary>
public event CheckBoxXChangeEventHandler CheckedChangedEx;
/// <summary>
/// Occurs after Checked property is changed. This event is provided for the Windows Forms data binding support. You can use CheckedChangedEx to get extended information about the changed.
/// </summary>
public event EventHandler CheckedChanged;
/// <summary>
/// Occurs after Checked property is changed. This event is provided for the Windows Forms data binding support. You can use CheckedChangedEx to get extended information about the changed.
/// </summary>
public event EventHandler CheckValueChanged;
#endregion
#region Constructor, Dispose
public CheckBoxX()
{
this.SetStyle(ControlStyles.Selectable, true);
m_CheckBox = new CheckBoxItem();
m_CheckBox.VerticalPadding = 0;
m_CheckBox.Style = eDotNetBarStyle.Office2007;
m_CheckBox.CheckedChanging += new CheckBoxChangeEventHandler(OnCheckedChanging);
m_CheckBox.CheckedChanged += new CheckBoxChangeEventHandler(OnCheckedChanged);
this.HostItem = m_CheckBox;
}
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets the size of the check or radio sign. Default value is 13x13. Minimum value is 6x6.
/// </summary>
[Category("Appearance"), Description("Indicates size of the check or radio sign. Default value is 13x13.")]
public Size CheckSignSize
{
get { return m_CheckBox.CheckSignSize; }
set { m_CheckBox.CheckSignSize = value; this.RecalcLayout(); this.Invalidate(); }
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeCheckSignSize()
{
return m_CheckBox.ShouldSerializeCheckSignSize();
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetCheckSignSize()
{
this.CheckSignSize = new Size(13, 13);
}
/// <summary>
/// Gets or sets whether text-markup support is enabled for controls Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the control instead of it being parsed as text-markup.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether text-markup support is enabled for controls Text property.")]
public bool EnableMarkup
{
get { return m_CheckBox.EnableMarkup; }
set
{
m_CheckBox.EnableMarkup = value;
}
}
protected override MouseButtons MouseDownFocusButtons
{
get { return MouseButtons.Left | MouseButtons.Right | MouseButtons.Middle | MouseButtons.XButton1 | MouseButtons.XButton2; }
}
//protected override void OnMouseDown(MouseEventArgs e)
//{
// if (!this.Focused)
// this.Select();
// base.OnMouseDown(e);
//}
//protected override void OnEnter(EventArgs e)
//{
// if (this.CheckBoxStyle == eCheckBoxStyle.RadioButton && Control.MouseButtons == MouseButtons.None && WinApi.GetKeyState(9) < 0 && this.AutoCheck)
// {
// m_CheckBox.SetChecked(true, eEventSource.Keyboard);
// }
// base.OnEnter(e);
//}
/// <summary>
/// Invokes the CheckedChanged event.
/// </summary>
private void OnCheckedChanged(object sender, CheckBoxChangeEventArgs e)
{
CheckBoxX previous = null;
if (m_CheckBox.CheckBoxStyle == eCheckBoxStyle.RadioButton && m_CheckBox.Checked && this.Parent != null)
{
foreach (Control c in this.Parent.Controls)
{
if (c == this)
{
//c.TabStop = true;
continue;
}
CheckBoxX b = c as CheckBoxX;
if (b != null && b.Checked && b.CheckBoxStyle == eCheckBoxStyle.RadioButton)
{
b.Checked = false;
//b.TabStop = false;
previous = b;
}
}
}
if (this.Command != null)
this.Command.Checked = this.Checked;
CheckBoxXChangeEventArgs e1 = new CheckBoxXChangeEventArgs(previous, this, e.EventSource);
if (CheckedChangedEx != null)
CheckedChangedEx(this, e1);
if (CheckedChanged != null)
CheckedChanged(this, new EventArgs());
if (GetCheckState(m_CheckValue) != this.CheckState)
m_CheckValue = GetCheckValue(this.CheckState);
if (CheckValueChanged != null)
CheckValueChanged(this, new EventArgs());
ExecuteCommand();
}
/// <summary>
/// Invokes CheckedChanging event.
/// </summary>
private void OnCheckedChanging(object sender, CheckBoxChangeEventArgs e)
{
CheckBoxXChangeEventArgs e1 = new CheckBoxXChangeEventArgs(null, this, e.EventSource);
if (m_CheckBox.CheckBoxStyle == eCheckBoxStyle.RadioButton && !m_CheckBox.Checked && this.Parent != null)
{
CheckBoxX b = null;
foreach (Control c in this.Parent.Controls)
{
if (c == this)
continue;
b = c as CheckBoxX;
if (b != null && b.Checked && b.CheckBoxStyle == eCheckBoxStyle.RadioButton)
{
break;
}
}
e1 = new CheckBoxXChangeEventArgs(b, this, e.EventSource);
}
if (CheckedChanging != null)
{
CheckedChanging(this, e1);
e.Cancel = e1.Cancel;
}
}
/// <summary>
/// Gets or sets the appearance style of the item. Default value is CheckBox. Item can also assume the style of radio-button.
/// </summary>
[Browsable(true), DefaultValue(eCheckBoxStyle.CheckBox), Category("Appearance"), Description("Indicates appearance style of the item. Default value is CheckBox. Item can also assume the style of radio-button.")]
public eCheckBoxStyle CheckBoxStyle
{
get { return m_CheckBox.CheckBoxStyle; }
set
{
m_CheckBox.CheckBoxStyle = value;
}
}
/// <summary>
/// Gets or sets the check box position relative to the text. Default value is Left.
/// </summary>
[Browsable(true), DefaultValue(eCheckBoxPosition.Left), Category("Appearance"), Description("Indicates the check box position relative to the text.")]
public eCheckBoxPosition CheckBoxPosition
{
get { return m_CheckBox.CheckBoxPosition; }
set
{
m_CheckBox.CheckBoxPosition = value;
}
}
/// <summary>
/// Gets or set a value indicating whether the button is in the checked state.
/// </summary>
[Browsable(true), Bindable(true), DevCoBrowsable(true), Category("Appearance"), Description("Indicates whether item is checked or not."), DefaultValue(false)]
public virtual bool Checked
{
get
{
return m_CheckBox.Checked;
}
set
{
m_CheckBox.Checked = value;
}
}
/// <summary>
/// Gets or sets whether text assigned to the check box is visible. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether text assigned to the check box is visible.")]
public bool TextVisible
{
get { return m_CheckBox.TextVisible; }
set
{
m_CheckBox.TextVisible = value;
this.RecalcLayout();
}
}
/// <summary>
/// Gets or sets the text color. Default value is Color.Empty which indicates that default color is used.
/// </summary>
[Browsable(true), Category("Appearance"), Description("Indicates text color.")]
public Color TextColor
{
get { return m_CheckBox.TextColor; }
set
{
m_CheckBox.TextColor = value;
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTextColor()
{
return !m_CheckBox.TextColor.IsEmpty;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTextColor()
{
this.TextColor = Color.Empty;
}
[Browsable(false)]
public override Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Space && this.Enabled && this.AutoCheck)
{
if (this.CheckBoxStyle == eCheckBoxStyle.CheckBox)
SetChecked(!this.Checked, eEventSource.Keyboard);
else if (!this.Checked)
SetChecked(true, eEventSource.Keyboard);
}
base.OnKeyDown(e);
}
private void SetChecked(bool newValue, eEventSource source)
{
m_CheckBox.SetChecked(newValue, source);
}
private void SetChecked(CheckState newValue, eEventSource source)
{
m_CheckBox.SetChecked(newValue, source);
}
/// <summary>
/// Gets or sets the text associated with the control.
/// </summary>
[Browsable(true), Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor)), Category("Appearance"), Description("Indicates text associated with this button.."), Localizable(true), DefaultValue("")]
public override string Text
{
get { return base.Text; }
set { base.Text = value; }
}
#if FRAMEWORK20
[Localizable(true), Browsable(false)]
public new System.Windows.Forms.Padding Padding
{
get { return base.Padding; }
set { base.Padding = value; }
}
public override Size GetPreferredSize(Size proposedSize)
{
if (!BarFunctions.IsHandleValid(this))
return base.GetPreferredSize(proposedSize);
if (this.Text.Length == 0)
return base.GetPreferredSize(proposedSize);
m_CheckBox.RecalcSize();
Size s = m_CheckBox.Size;
s.Width += 2;
s.Height += 2;
if (!this.TextVisible) s.Width += 2;
m_CheckBox.Bounds = GetItemBounds();
return s;
}
/// <summary>
/// Gets or sets a value indicating whether the control is automatically resized to display its entire contents. You can set MaximumSize.Width property to set the maximum width used by the control.
/// </summary>
[Browsable(true), DefaultValue(false), EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
if (this.AutoSize != value)
{
base.AutoSize = value;
AdjustSize();
}
}
}
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
if (this.AutoSize)
{
Size preferredSize = base.PreferredSize;
width = preferredSize.Width;
height = preferredSize.Height;
}
base.SetBoundsCore(x, y, width, height, specified);
}
private void AdjustSize()
{
if (this.AutoSize)
{
this.Size = base.PreferredSize;
}
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
this.AdjustSize();
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (this.AutoSize)
this.AdjustSize();
}
#endif
/// <summary>
/// Gets or sets a value indicating whether the CheckBox will allow three check states rather than two. If the ThreeState property is set to true
/// CheckState property should be used instead of Checked property to set the extended state of the control.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(false), Description("Indicates whether the CheckBox will allow three check states rather than two.")]
public bool ThreeState
{
get { return m_CheckBox.ThreeState; }
set { m_CheckBox.ThreeState = value; }
}
/// <summary>
/// Specifies the state of a control, such as a check box, that can be checked, unchecked, or set to an indeterminate state.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(CheckState.Unchecked), Description("Specifies the state of a control, such as a check box, that can be checked, unchecked, or set to an indeterminate state")]
public CheckState CheckState
{
get { return m_CheckBox.CheckState; }
set { m_CheckBox.CheckState = value; }
}
/// <summary>
/// Gets the underlying CheckBoxItem
/// </summary>
internal CheckBoxItem CheckBoxItem
{
get { return (m_CheckBox); }
}
private bool _EnableMnemonicWithAltKeyOnly = false;
/// <summary>
/// Gets or sets whether mnemonic character assigned to control is processed only if Alt key is pressed. Default value is false which indicate that Alt key is not required.
/// </summary>
[DefaultValue(false), Category("Behavior"), Description("Indicates whether mnemonic character assigned to control is processed only if Alt key is pressed")]
public bool EnableMnemonicWithAltKeyOnly
{
get { return _EnableMnemonicWithAltKeyOnly; }
set
{
_EnableMnemonicWithAltKeyOnly = value;
}
}
protected override bool ProcessMnemonic(char charCode)
{
if (AutoCheck && CanSelect && IsMnemonic(charCode, this.Text) && this.Enabled &&
(!_EnableMnemonicWithAltKeyOnly || Control.ModifierKeys == Keys.Alt || this.Focused) && !m_CheckBox.IsUsingTextMarkup)
{
if (Focus())
{
if (this.CheckBoxStyle == eCheckBoxStyle.CheckBox)
SetChecked(!this.Checked, eEventSource.Keyboard);
else if (!this.Checked)
SetChecked(true, eEventSource.Keyboard);
return true;
}
}
return false;
}
#endregion
#region Data-Binding Support
/// <summary>
/// Gets or set whether the Checked values and the item appearance are automatically changed when the Check-Box is clicked. Default value is true.
/// </summary>
[DefaultValue(true), Category("Behavior"), Description("Indicates whether the Checked values and the item appearance are automatically changed when the Check-Box is clicked.")]
public bool AutoCheck
{
get { return m_CheckBox.AutoCheck; }
set
{
m_CheckBox.AutoCheck = value;
}
}
/// <summary>
/// Gets or sets the object that represents the Checked state of control.
/// </summary>
[DefaultValue("N"), Bindable(true), RefreshProperties(RefreshProperties.All), TypeConverter(typeof(StringConverter)), Description("Indicates object that represents the Checked state of control.")]
public object CheckValue
{
get { return m_CheckValue; }
set
{
m_CheckValue = value;
OnCheckValueChanged();
}
}
private void OnCheckValueChanged()
{
CheckState cs = GetCheckState(m_CheckValue);
this.CheckState = cs;
}
private bool IsNull(object value)
{
return value == null || value is string && (string)value == string.Empty && m_ConsiderEmptyStringAsNull ||
value == DBNull.Value;
}
private object GetCheckValue(CheckState cs)
{
if (cs == CheckState.Indeterminate)
return m_CheckValueIndeterminate;
if (cs == CheckState.Unchecked)
return m_CheckValueUnchecked;
return m_CheckValueChecked;
}
private CheckState GetCheckState(object value)
{
if (m_CheckValueIndeterminate == null && IsNull(value) || m_CheckValueIndeterminate!=null && m_CheckValueIndeterminate.Equals(value))
{
return CheckState.Indeterminate;
}
else if (m_CheckValueChecked == null && IsNull(value) || m_CheckValueChecked!=null && m_CheckValueChecked.Equals(value))
{
return CheckState.Checked;
}
else if (m_CheckValueUnchecked == null && IsNull(value) || m_CheckValueUnchecked!=null && m_CheckValueUnchecked.Equals(value))
{
return CheckState.Unchecked;
}
else
{
if (value is System.Data.SqlTypes.SqlBoolean)
{
System.Data.SqlTypes.SqlBoolean sqlBool = (System.Data.SqlTypes.SqlBoolean)value;
if (sqlBool.IsTrue)
return CheckState.Checked;
else if (sqlBool.IsNull)
return CheckState.Indeterminate;
else
return CheckState.Unchecked;
}
else if (value is int? && this.ThreeState)
{
if (value == null) return CheckState.Indeterminate;
if (((int?)value).Value == 0)
return CheckState.Unchecked;
return CheckState.Checked;
}
else if (value is int)
{
if (this.ThreeState && (int)value == -1)
return CheckState.Indeterminate;
return ((int)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is long)
{
if (this.ThreeState && (long)value == -1)
return CheckState.Indeterminate;
return ((long)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is short)
{
if (this.ThreeState && (short)value == -1)
return CheckState.Indeterminate;
return ((short)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is float)
{
if (this.ThreeState && (float)value == -1)
return CheckState.Indeterminate;
return ((float)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is double)
{
if (this.ThreeState && (double)value == -1)
return CheckState.Indeterminate;
return ((double)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is byte)
{
return ((byte)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is uint)
{
return ((uint)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is ulong)
{
return ((ulong)value) == 0 ? CheckState.Unchecked : CheckState.Checked;
}
else if (value is bool)
{
return ((bool)value) == false ? CheckState.Unchecked : CheckState.Checked;
}
return CheckState.Indeterminate;
}
}
/// <summary>
/// Gets or sets whether empty string is consider as null value during CheckValue value comparison. Default value is true.
/// </summary>
[DefaultValue(true), Category("Behavior"), Browsable(true), Description("Indicates whether empty string is consider as null value during CheckValue value comparison.")]
public bool ConsiderEmptyStringAsNull
{
get { return m_ConsiderEmptyStringAsNull; }
set { m_ConsiderEmptyStringAsNull = value; }
}
/// <summary>
/// Gets or sets the value that represents the Indeterminate state of check box when CheckValue property is set to that value. Default value is null.
/// </summary>
[Browsable(true), DefaultValue(null), Category("Behavior"), TypeConverter(typeof(StringConverter)), Description("Represents the Indeterminate state value of check box when CheckValue property is set to that value")]
public object CheckValueIndeterminate
{
get { return m_CheckValueIndeterminate; }
set { m_CheckValueIndeterminate = value; OnCheckValueChanged(); }
}
/// <summary>
/// Gets or sets the value that represents the Checked state of check box when CheckValue property is set to that value. Default value is null.
/// </summary>
[Browsable(true), DefaultValue("Y"), Category("Behavior"), TypeConverter(typeof(StringConverter)), Description("Represents the Checked state value of check box when CheckValue property is set to that value")]
public object CheckValueChecked
{
get { return m_CheckValueChecked; }
set { m_CheckValueChecked = value; OnCheckValueChanged(); }
}
/// <summary>
/// Gets or sets the value that represents the Unchecked state of check box when CheckValue property is set to that value. Default value is null.
/// </summary>
[Browsable(true), DefaultValue("N"), Category("Behavior"), TypeConverter(typeof(StringConverter)), Description("Represents the Unchecked state value of check box when CheckValue property is set to that value")]
public object CheckValueUnchecked
{
get { return m_CheckValueUnchecked; }
set { m_CheckValueUnchecked = value; OnCheckValueChanged(); }
}
/// <summary>
/// Gets or sets the custom image that is displayed instead default check box representation when check box is checked.
/// </summary>
[DefaultValue(null), Category("CheckBox Images"), Description("Indicates custom image that is displayed instead default check box representation when check box is checked")]
public Image CheckBoxImageChecked
{
get { return m_CheckBox.CheckBoxImageChecked; }
set
{
m_CheckBox.CheckBoxImageChecked = value;
}
}
/// <summary>
/// Gets or sets the custom image that is displayed instead default check box representation when check box is unchecked.
/// </summary>
[DefaultValue(null), Category("CheckBox Images"), Description("Indicates custom image that is displayed instead default check box representation when check box is unchecked")]
public Image CheckBoxImageUnChecked
{
get { return m_CheckBox.CheckBoxImageUnChecked; }
set
{
m_CheckBox.CheckBoxImageUnChecked = value;
}
}
/// <summary>
/// Gets or sets the custom image that is displayed instead default check box representation when check box is in indeterminate state.
/// </summary>
[DefaultValue(null), Category("CheckBox Images"), Description("Indicates custom image that is displayed instead default check box representation when check box is in indeterminate state")]
public Image CheckBoxImageIndeterminate
{
get { return m_CheckBox.CheckBoxImageIndeterminate; }
set
{
m_CheckBox.CheckBoxImageIndeterminate = value;
}
}
#endregion
#region ICommandSource Members
protected virtual void ExecuteCommand()
{
if (_Command == null) return;
CommandManager.ExecuteCommand(this);
}
/// <summary>
/// Gets or sets the command assigned to the item. Default value is null.
/// <remarks>Note that if this property is set to null Enabled property will be set to false automatically to disable the item.</remarks>
/// </summary>
[DefaultValue(null), Category("Commands"), Description("Indicates the command assigned to the item.")]
public Command Command
{
get { return (Command)((ICommandSource)this).Command; }
set
{
((ICommandSource)this).Command = value;
}
}
private ICommand _Command = null;
//[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
ICommand ICommandSource.Command
{
get
{
return _Command;
}
set
{
bool changed = false;
if (_Command != value)
changed = true;
if (_Command != null)
CommandManager.UnRegisterCommandSource(this, _Command);
_Command = value;
if (value != null)
CommandManager.RegisterCommand(this, value);
if (changed)
OnCommandChanged();
}
}
/// <summary>
/// Called when Command property value changes.
/// </summary>
protected virtual void OnCommandChanged()
{
Command command = this.Command;
if (command != null && command.Checked != this.Checked)
{
SetChecked(command.Checked, eEventSource.Code);
}
}
private object _CommandParameter = null;
/// <summary>
/// Gets or sets user defined data value that can be passed to the command when it is executed.
/// </summary>
[Browsable(true), DefaultValue(null), Category("Commands"), Description("Indicates user defined data value that can be passed to the command when it is executed."), System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter)), System.ComponentModel.Localizable(true)]
public object CommandParameter
{
get
{
return _CommandParameter;
}
set
{
_CommandParameter = value;
}
}
#endregion
}
/// <summary>
/// Delegate for OptionGroupChanging event.
/// </summary>
public delegate void CheckBoxXChangeEventHandler(object sender, CheckBoxXChangeEventArgs e);
#region CheckBoxXChangeEventArgs
/// <summary>
/// Represents event arguments for OptionGroupChanging event.
/// </summary>
public class CheckBoxXChangeEventArgs : EventArgs
{
/// <summary>
/// Set to true to cancel the checking on NewChecked button.
/// </summary>
public bool Cancel = false;
/// <summary>
/// Check-box that will become checked if operation is not cancelled.
/// </summary>
public readonly CheckBoxX NewChecked;
/// <summary>
/// Check-box that is currently checked and which will be unchecked if operation is not cancelled. This property will have only valid values for eCheckBoxStyle.RadioButton style CheckBoxItems.
/// </summary>
public readonly CheckBoxX OldChecked;
/// <summary>
/// Indicates the action that has caused the event.
/// </summary>
public readonly eEventSource EventSource = eEventSource.Code;
/// <summary>
/// Default constructor.
/// </summary>
public CheckBoxXChangeEventArgs(CheckBoxX oldchecked, CheckBoxX newchecked, eEventSource eventSource)
{
NewChecked = newchecked;
OldChecked = oldchecked;
EventSource = eventSource;
}
}
#endregion
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

View File

@@ -0,0 +1,474 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(CircularProgress), "Controls.CircularProgress.ico"), ToolboxItem(true), DefaultEvent("ValueChanged")]
public class CircularProgress : BaseItemControl
{
#region Constructor
private CircularProgressItem _Item = null;
/// <summary>
/// Initializes a new instance of the CircularProgress class.
/// </summary>
public CircularProgress()
{
_Item = new CircularProgressItem();
_Item.ValueChanged += new EventHandler(ItemValueChanged);
_Item.TextVisible = false;
this.HostItem = _Item;
}
#endregion
#region Implementation
protected override void Dispose(bool disposing)
{
_Item.Dispose();
base.Dispose(disposing);
}
protected override void RecalcSize()
{
_Item.Diameter = Math.Min(this.Width, this.Height);
base.RecalcSize();
}
private void ItemValueChanged(object sender, EventArgs e)
{
OnValueChanged(e);
}
/// <summary>
/// Occurs when Value property has changed.
/// </summary>
public event EventHandler ValueChanged;
/// <summary>
/// Raises ValueChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnValueChanged(EventArgs e)
{
EventHandler handler = ValueChanged;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Gets or sets the circular progress bar type.
/// </summary>
[DefaultValue(eCircularProgressType.Line), Category("Appearance"), Description("Indicates circular progress bar type.")]
public eCircularProgressType ProgressBarType
{
get { return _Item.ProgressBarType; }
set
{
_Item.ProgressBarType = value;
}
}
/// <summary>
/// Gets or sets the maximum value of the progress bar.
/// </summary>
[Description("Indicates maximum value of the progress bar."), Category("Behavior"), DefaultValue(100)]
public int Maximum
{
get { return _Item.Maximum; }
set
{
_Item.Maximum = value;
}
}
/// <summary>
/// Gets or sets the minimum value of the progress bar.
/// </summary>
[Description("Indicates minimum value of the progress bar."), Category("Behavior"), DefaultValue(0)]
public int Minimum
{
get { return _Item.Minimum; }
set
{
_Item.Minimum = value;
}
}
/// <summary>
/// Gets or sets the color of the progress percentage text.
/// </summary>
[Category("Appearance"), Description("Indicates color of progress percentage text")]
public Color ProgressTextColor
{
get { return _Item.ProgressTextColor; }
set { _Item.ProgressTextColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeProgressTextColor()
{
return _Item.ShouldSerializeProgressTextColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetProgressTextColor()
{
_Item.ResetProgressTextColor();
}
/// <summary>
/// Gets or sets whether text that displays the progress bar completion percentage text is visible. Default value is false.
/// </summary>
[DefaultValue(false), Category("Appearance"), Description("Indicates whether text that displays the progress bar completion percentage text is visible")]
public bool ProgressTextVisible
{
get { return _Item.ProgressTextVisible; }
set
{
_Item.ProgressTextVisible = value;
}
}
/// <summary>
/// Gets or sets the text displayed on top of the circular progress bar.
/// </summary>
[DefaultValue(""), Category("Appearance"), Description("Indicates text displayed on top of the circular progress bar.")]
public string ProgressText
{
get { return _Item.ProgressText; }
set
{
_Item.ProgressText = value;
}
}
/// <summary>
/// Gets or sets the current value of the progress bar.
/// </summary>
[Description("Indicates current value of the progress bar."), Category("Behavior"), DefaultValue(0)]
public int Value
{
get { return _Item.Value; }
set
{
_Item.Value = value;
}
}
/// <summary>
/// Gets or sets whether endless type progress bar is running.
/// </summary>
[Browsable(false), DefaultValue(false)]
public bool IsRunning
{
get { return _Item.IsRunning; }
set
{
_Item.IsRunning = value;
}
}
/// <summary>
/// Gets or sets the color of the color of progress indicator.
/// </summary>
[Category("Columns"), Description("Indicates color of progress indicator.")]
public Color ProgressColor
{
get { return _Item.ProgressColor; }
set { _Item.ProgressColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeProgressColor()
{
return _Item.ShouldSerializeProgressColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetProgressColor()
{
_Item.ResetProgressColor();
}
///// <summary>
///// Gets or sets circular progress indicator diameter in pixels.
///// </summary>
//[DefaultValue(24), Category("Appearance"), Description("Indicates circular progress indicator diameter in pixels.")]
//public int Diameter
//{
// get { return _Item.Diameter; }
// set
// {
// _Item.Diameter = value;
// this.RecalcLayout();
// }
//}
///// <summary>
///// Gets or sets the text position in relation to the circular progress indicator.
///// </summary>
//[DefaultValue(eTextPosition.Left), Category("Appearance"), Description("Indicatesd text position in relation to the circular progress indicator.")]
//public eTextPosition TextPosition
//{
// get { return _Item.TextPosition; }
// set
// {
// _Item.TextPosition = value;
// }
//}
///// <summary>
///// Gets or sets whether text/label displayed next to the item is visible.
///// </summary>
//[DefaultValue(true), Category("Appearance"), Description("Indicates whether caption/label set using Text property is visible.")]
//public bool TextVisible
//{
// get { return _Item.TextVisible; }
// set
// {
// _Item.TextVisible = value;
// }
//}
///// <summary>
///// Gets or sets the suggested text-width. If you want to make sure that text you set wraps over multiple lines you can set suggested text-width so word break is performed.
///// </summary>
//[DefaultValue(0), Category("Appearance"), Description("Indicates suggested text-width. If you want to make sure that text you set wraps over multiple lines you can set suggested text-width so word break is performed.")]
//public int TextWidth
//{
// get { return _Item.TextWidth; }
// set
// {
// _Item.TextWidth = value;
// }
//}
///// <summary>
///// Gets or sets text padding.
///// </summary>
//[Browsable(true), Category("Appearance"), Description("Gets or sets text padding."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
//public Padding TextPadding
//{
// get { return _Item.TextPadding; }
//}
//[EditorBrowsable(EditorBrowsableState.Never)]
//public bool ShouldSerializeTextPadding()
//{
// return _Item.ShouldSerializeTextPadding();
//}
//[EditorBrowsable(EditorBrowsableState.Never)]
//public void ResetTextPadding()
//{
// _Item.ResetTextPadding();
//}
//protected override void OnForeColorChanged(EventArgs e)
//{
// _Item.TextColor = this.ForeColor;
// base.OnForeColorChanged(e);
//}
/// <summary>
/// Gets or sets the color of the pie progress bar dark border.
/// </summary>
[Category("Pie"), Description("Indicates color of pie progress bar dark border.")]
public Color PieBorderDark
{
get { return _Item.PieBorderDark; }
set { _Item.PieBorderDark = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializePieBorderDark()
{
return _Item.ShouldSerializePieBorderDark();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetPieBorderDark()
{
_Item.ResetPieBorderDark();
}
/// <summary>
/// Gets or sets the color of the pie progress bar light border.
/// </summary>
[Category("Pie"), Description("Indicates color of pie progress bar light border. ")]
public Color PieBorderLight
{
get { return _Item.PieBorderLight; }
set { _Item.PieBorderLight = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializePieBorderLight()
{
return _Item.ShouldSerializePieBorderLight();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetPieBorderLight()
{
_Item.ResetPieBorderLight();
}
/// <summary>
/// Gets or sets the color of the spoke progress bar dark border.
/// </summary>
[Category("Spoke"), Description("Indicates color of spoke progress bar dark border.")]
public Color SpokeBorderDark
{
get { return _Item.SpokeBorderDark; }
set { _Item.SpokeBorderDark = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSpokeBorderDark()
{
return _Item.ShouldSerializeSpokeBorderDark();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSpokeBorderDark()
{
_Item.ResetSpokeBorderDark();
}
/// <summary>
/// Gets or sets the color of the spoke progress bar light border.
/// </summary>
[Category("Spoke"), Description("Indicates color of spoke progress bar light border..")]
public Color SpokeBorderLight
{
get { return _Item.SpokeBorderLight; }
set { _Item.SpokeBorderLight = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSpokeBorderLight()
{
return _Item.ShouldSerializeSpokeBorderLight();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSpokeBorderLight()
{
_Item.ResetSpokeBorderLight();
}
/// <summary>
/// Gets or sets format string for progress value.
/// </summary>
[DefaultValue("{0}%"), Category("Appearance"), Description("Indicates format string for progress value.")]
public string ProgressTextFormat
{
get { return _Item.ProgressTextFormat; }
set
{
_Item.ProgressTextFormat = value;
}
}
/// <summary>
/// Gets or sets the animation speed for endless running progress. Lower number means faster running.
/// </summary>
[DefaultValue(100), Description("Indicates the animation speed for endless running progress. Lower number means faster running."), Category("Behavior")]
public int AnimationSpeed
{
get
{
return _Item.AnimationSpeed;
}
set
{
_Item.AnimationSpeed = value;
}
}
/// <summary>
/// Starts the progress bar loop for endless type progress bar. Progress bar will continue to run until Stop() method is called.
/// </summary>
public void Start()
{
_Item.Start();
}
/// <summary>
/// Stops the progress bar loop for endless type progress bar.
/// </summary>
public void Stop()
{
_Item.Stop(false);
}
#endregion
#region Property-Hiding
[Browsable(false)]
public override eDotNetBarStyle Style
{
get { return base.Style; }
set { base.Style = value;}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Color ForeColor
{
get { return base.ForeColor; }
set { base.ForeColor = value; }
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override RightToLeft RightToLeft
{
get { return base.RightToLeft; }
set { base.RightToLeft = value; }
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Image BackgroundImage
{
get
{
return base.BackgroundImage;
}
set
{
base.BackgroundImage = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override ImageLayout BackgroundImageLayout
{
get
{
return base.BackgroundImageLayout;
}
set
{
base.BackgroundImageLayout = value;
}
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

View File

@@ -0,0 +1,558 @@
using DevComponents.DotNetBar.Rendering;
using DevComponents.Editors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(CollapsibleSplitContainer), "Controls.CollapsibleSplitContainer.ico")]
public class CollapsibleSplitContainer : SplitContainer
{
#region Constructor
/// <summary>
/// Initializes a new instance of the CollapsibleSplitContainer class.
/// </summary>
public CollapsibleSplitContainer()
{
ControlStyles cs = ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer;
this.SetStyle(cs, true);
object[] objArgs = new object[] { cs, true };
MethodInfo mi = typeof(Control).GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance);
if (mi != null)
{
mi.Invoke(this.Panel1, objArgs);
mi.Invoke(this.Panel2, objArgs);
}
this.SplitterWidth = 20;
_OverrideCursorPropInfo = typeof(SplitContainer).GetProperty("OverrideCursor", BindingFlags.NonPublic | BindingFlags.Instance);
this.SplitterMoved += SplitterMovedHandler;
}
protected override void Dispose(bool disposing)
{
this.SplitterMoved -= SplitterMovedHandler;
base.Dispose(disposing);
}
#endregion
#region Implementation
private Rectangle _NearCollapseButton = Rectangle.Empty;
private Rectangle _FarCollapseButton = Rectangle.Empty;
private eButtonState _NearCollapseButtonState = eButtonState.Normal, _FarCollapseButtonState = eButtonState.Normal;
private const int ButtonSpacing = 2;
private void UpdateButtonLayout()
{
Rectangle r = this.SplitterRectangle;
Size buttonSize = new Size(this.SplitterWidth, this.SplitterWidth);
if (this.Orientation == System.Windows.Forms.Orientation.Horizontal)
{
if (_ButtonPosition == eSplitterButtonPosition.Near)
{
_NearCollapseButton = new Rectangle(r.X, r.Y, buttonSize.Width, buttonSize.Height);
_FarCollapseButton = new Rectangle(_NearCollapseButton.Right + ButtonSpacing, r.Y, buttonSize.Width, buttonSize.Height);
}
else if (_ButtonPosition == eSplitterButtonPosition.Center)
{
_NearCollapseButton = new Rectangle(r.X + (r.Width - (buttonSize.Width * 2 + ButtonSpacing)) / 2, r.Y, buttonSize.Width, buttonSize.Height);
_FarCollapseButton = new Rectangle(_NearCollapseButton.Right + ButtonSpacing, r.Y, buttonSize.Width, buttonSize.Height);
}
else if (_ButtonPosition == eSplitterButtonPosition.Far)
{
_NearCollapseButton = new Rectangle(r.Right - buttonSize.Width * 2 - ButtonSpacing, r.Y, buttonSize.Width, buttonSize.Height);
_FarCollapseButton = new Rectangle(_NearCollapseButton.Right + ButtonSpacing, r.Y, buttonSize.Width, buttonSize.Height);
}
}
else
{
if (_ButtonPosition == eSplitterButtonPosition.Near)
{
_NearCollapseButton = new Rectangle(r.X, r.Y, buttonSize.Width, buttonSize.Height);
_FarCollapseButton = new Rectangle(r.X, _NearCollapseButton.Bottom + ButtonSpacing, buttonSize.Width, buttonSize.Height);
}
else if (_ButtonPosition == eSplitterButtonPosition.Center)
{
_NearCollapseButton = new Rectangle(r.X, r.Y + (r.Height - (buttonSize.Height * 2 + ButtonSpacing)) / 2, buttonSize.Width, buttonSize.Height);
_FarCollapseButton = new Rectangle(r.X, _NearCollapseButton.Bottom + ButtonSpacing, buttonSize.Width, buttonSize.Height);
}
else if (_ButtonPosition == eSplitterButtonPosition.Far)
{
_NearCollapseButton = new Rectangle(r.X, r.Bottom - buttonSize.Height * 2 - ButtonSpacing, buttonSize.Width, buttonSize.Height);
_FarCollapseButton = new Rectangle(r.X, _NearCollapseButton.Bottom + ButtonSpacing, buttonSize.Width, buttonSize.Height);
}
}
}
protected override void OnPaint(PaintEventArgs e)
{
UpdateButtonLayout();
base.OnPaint(e);
Graphics g = e.Graphics;
bool isHorizontal = this.Orientation == System.Windows.Forms.Orientation.Horizontal;
if (_NearCollapseButtonState != eButtonState.Hidden)
{
Office2007ButtonItemStateColorTable ct = GetOffice2007StateColorTable(_NearCollapseButtonState);
Office2007ButtonItemPainter.PaintBackground(g, ct, _NearCollapseButton, RoundRectangleShapeDescriptor.RectangleShape);
Rectangle r = _NearCollapseButton;
r.Inflate(-2, -2);
TextDrawing.DrawStringLegacy(g, isHorizontal ? "\uf077" : "\uf053", Symbols.GetFont(9f, eSymbolSet.Awesome),
ct.Text, r, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
}
if (_FarCollapseButtonState != eButtonState.Hidden)
{
Office2007ButtonItemStateColorTable ct = GetOffice2007StateColorTable(_FarCollapseButtonState);
Office2007ButtonItemPainter.PaintBackground(g, ct, _FarCollapseButton, RoundRectangleShapeDescriptor.RectangleShape);
Rectangle r = _FarCollapseButton;
r.Inflate(-2, -2);
TextDrawing.DrawStringLegacy(g, isHorizontal ? "\uf078" : "\uf054", Symbols.GetFont(9f, eSymbolSet.Awesome),
ct.Text, r, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
}
}
protected Office2007ButtonItemStateColorTable GetOffice2007StateColorTable(eButtonState state)
{
if (GlobalManager.Renderer is Office2007Renderer)
{
Office2007ColorTable ct = ((Office2007Renderer)GlobalManager.Renderer).ColorTable;
Office2007ButtonItemColorTable buttonColorTable = ct.ButtonItemColors[Enum.GetName(typeof(eButtonColor), eButtonColor.OrangeWithBackground)];
if (!this.Enabled || state == eButtonState.Disabled)
return buttonColorTable.Disabled;
else if (state == eButtonState.MouseDownLeft)
return buttonColorTable.Pressed;
else if (state == eButtonState.MouseOver)
return buttonColorTable.MouseOver;
else
return buttonColorTable.Default;
}
return null;
}
private Orientation _CurrentOrientation = Orientation.Vertical;
protected override void OnLayout(LayoutEventArgs e)
{
base.OnLayout(e);
if (_CurrentOrientation != this.Orientation)
{
_CurrentOrientation = this.Orientation;
UpdateButtonLayout();
}
Invalidate();
}
private bool IsButtonActive(eButtonState state)
{
return state != eButtonState.Hidden && state != eButtonState.Disabled;
}
private Cursor _OriginalCursor = null;
protected override void OnMouseMove(MouseEventArgs e)
{
if (IsButtonActive(_NearCollapseButtonState))
{
if (_NearCollapseButton.Contains(e.Location))
{
if (_NearCollapseButtonState == eButtonState.Normal)
{
_NearCollapseButtonState = eButtonState.MouseOver;
this.Invalidate();
}
}
else
{
_NearCollapseButtonState = eButtonState.Normal;
this.Invalidate();
}
}
if (IsButtonActive(_FarCollapseButtonState))
{
if (_FarCollapseButton.Contains(e.Location))
{
if (_FarCollapseButtonState == eButtonState.Normal)
{
_FarCollapseButtonState = eButtonState.MouseOver;
this.Invalidate();
}
}
else
{
_FarCollapseButtonState = eButtonState.Normal;
this.Invalidate();
}
}
if (_NearCollapseButton.Contains(e.Location) || _FarCollapseButton.Contains(e.Location))
{
if (_OriginalCursor == null && _OverrideCursorPropInfo != null)
{
_OriginalCursor = (Cursor)_OverrideCursorPropInfo.GetValue(this, null);
_OverrideCursorPropInfo.SetValue(this, Cursors.Default, null);
}
return;
}
RestoreOriginalCursor();
base.OnMouseMove(e);
}
private PropertyInfo _OverrideCursorPropInfo = null;
private void RestoreOriginalCursor()
{
if (_OriginalCursor != null)
{
_OverrideCursorPropInfo.SetValue(this, _OriginalCursor, null); ;
_OriginalCursor = null;
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (IsButtonActive(_NearCollapseButtonState))
{
if (_NearCollapseButton.Contains(e.Location) && e.Button == System.Windows.Forms.MouseButtons.Left)
{
_NearCollapseButtonState = eButtonState.MouseDownLeft;
this.Invalidate();
}
}
if (IsButtonActive(_FarCollapseButtonState))
{
if (_FarCollapseButton.Contains(e.Location) && e.Button == System.Windows.Forms.MouseButtons.Left)
{
_FarCollapseButtonState = eButtonState.MouseDownLeft;
this.Invalidate();
}
}
if (_NearCollapseButton.Contains(e.Location) || _FarCollapseButton.Contains(e.Location))
return;
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (IsButtonActive(_NearCollapseButtonState))
{
if (_NearCollapseButton.Contains(e.Location))
{
if (_NearCollapseButtonState == eButtonState.MouseDownLeft)
{
_NearCollapseButtonState = eButtonState.MouseOver;
// Trigger button action
NearCollapseButtonClick();
}
this.Invalidate();
}
}
if (IsButtonActive(_FarCollapseButtonState))
{
if (_FarCollapseButton.Contains(e.Location))
{
if (_FarCollapseButtonState == eButtonState.MouseDownLeft)
{
_FarCollapseButtonState = eButtonState.MouseOver;
// Trigger button action
FarCollapseButtonClick();
}
this.Invalidate();
}
}
if (_NearCollapseButton.Contains(e.Location) || _FarCollapseButton.Contains(e.Location))
return;
base.OnMouseUp(e);
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
this.Invalidate();
}
// <summary>
/// Occurs before near collapse button is clicked and allows you to cancel its action.
/// </summary>
[Description("Occurs before near collapse button is clicked and allows you to cancel its action.")]
public event CancelEventHandler BeforeNearCollapseButtonClick;
/// <summary>
/// Raises BeforeNearCollapseButtonClick event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnBeforeNearCollapseButtonClick(CancelEventArgs e)
{
CancelEventHandler handler = BeforeNearCollapseButtonClick;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Occurs after near collapse button is clicked.
/// </summary>
[Description("Occurs after near collapse button is clicked.")]
public event EventHandler NearCollapseButtonClicked;
/// <summary>
/// Raises NearCollapseButtonClick event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnNearCollapseButtonClicked(EventArgs e)
{
EventHandler handler = NearCollapseButtonClicked;
if (handler != null)
handler(this, e);
}
private int _OriginalSplitterDistance = 0;
private bool _IsPanel1Minimized = false;
private bool _IsPanel2Minimized = false;
private bool _InternalDistanceChange = false;
private void NearCollapseButtonClick()
{
CancelEventArgs e = new CancelEventArgs();
OnBeforeNearCollapseButtonClick(e);
if (e.Cancel) return;
if (_CollapseMode == eCollapseMode.PanelMinSize)
{
_InternalDistanceChange = true;
try
{
if (_IsPanel2Minimized)
{
this.SplitterDistance = _OriginalSplitterDistance;
_IsPanel2Minimized = false;
_FarCollapseButtonState = eButtonState.Normal;
}
else if (!_IsPanel1Minimized)
{
_OriginalSplitterDistance = this.SplitterDistance;
this.SplitterDistance = this.Panel1MinSize;
_IsPanel1Minimized = true;
_NearCollapseButtonState = eButtonState.Disabled;
}
}
finally
{
_InternalDistanceChange = false;
}
}
else
{
this.Panel1Collapsed = true;
}
OnNearCollapseButtonClicked(EventArgs.Empty);
}
/// <summary>
/// Occurs before far collapse button is clicked and allows you to cancel its action.
/// </summary>
[Description("Occurs before far collapse button is clicked and allows you to cancel its action.")]
public event CancelEventHandler BeforeFarCollapseButtonClick;
/// <summary>
/// Raises BeforeFarCollapseButtonClick event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnBeforeFarCollapseButtonClick(CancelEventArgs e)
{
CancelEventHandler handler = BeforeFarCollapseButtonClick;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Occurs after far collapse button is clicked.
/// </summary>
[Description("Occurs after far collapse button is clicked.")]
public event EventHandler FarCollapseButtonClicked;
/// <summary>
/// Raises FarCollapseButtonClick event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnFarCollapseButtonClicked(EventArgs e)
{
EventHandler handler = FarCollapseButtonClicked;
if (handler != null)
handler(this, e);
}
private void FarCollapseButtonClick()
{
CancelEventArgs e=new CancelEventArgs();
OnBeforeFarCollapseButtonClick(e);
if (e.Cancel) return;
if (_CollapseMode == eCollapseMode.PanelMinSize)
{
_InternalDistanceChange = true;
try
{
if (_IsPanel1Minimized)
{
this.SplitterDistance = _OriginalSplitterDistance;
_IsPanel1Minimized = false;
_NearCollapseButtonState = eButtonState.Normal;
}
else if (!_IsPanel2Minimized)
{
_OriginalSplitterDistance = this.SplitterDistance;
if (this.Orientation == System.Windows.Forms.Orientation.Vertical)
this.SplitterDistance = this.Width - this.Panel2MinSize;
else
this.SplitterDistance = this.Height - this.Panel2MinSize;
_IsPanel2Minimized = true;
_FarCollapseButtonState = eButtonState.Disabled;
}
}
finally
{
_InternalDistanceChange = false;
}
}
else
{
this.Panel2Collapsed = true;
}
OnFarCollapseButtonClicked(EventArgs.Empty);
}
private void SplitterMovedHandler(object sender, SplitterEventArgs e)
{
if (_InternalDistanceChange) return;
if(_IsPanel1Minimized)
{
_IsPanel1Minimized = false;
_NearCollapseButtonState = eButtonState.Normal;
}
else if (_IsPanel2Minimized)
{
_IsPanel2Minimized = false;
_FarCollapseButtonState = eButtonState.Normal;
}
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
if (IsButtonActive(_NearCollapseButtonState))
{
_NearCollapseButtonState = eButtonState.Normal;
}
if (IsButtonActive(_FarCollapseButtonState))
{
_FarCollapseButtonState = eButtonState.Normal;
}
RestoreOriginalCursor();
Invalidate();
base.OnMouseLeave(e);
}
private eSplitterButtonPosition _ButtonPosition = eSplitterButtonPosition.Near;
/// <summary>
/// Indicates position of buttons inside container.
/// </summary>
[DefaultValue(eSplitterButtonPosition.Near), Category("Appearance"), Description("Indicates position of buttons inside container.")]
public eSplitterButtonPosition ButtonPosition
{
get { return _ButtonPosition; }
set
{
if (value != _ButtonPosition)
{
eSplitterButtonPosition oldValue = _ButtonPosition;
_ButtonPosition = value;
OnButtonPositionChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when ButtonPosition property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnButtonPositionChanged(eSplitterButtonPosition oldValue, eSplitterButtonPosition newValue)
{
UpdateButtonLayout();
this.Invalidate();
//OnPropertyChanged(new PropertyChangedEventArgs("ButtonPosition"));
}
private eCollapseMode _CollapseMode = eCollapseMode.PanelMinSize;
/// <summary>
/// Specifies how panels are collapsed when collapse buttons are pressed.
/// </summary>
[DefaultValue(eCollapseMode.PanelMinSize), Category("Behavior"), Description("Specifies how panels are collapsed when collapse buttons are pressed.")]
public eCollapseMode CollapseMode
{
get { return _CollapseMode; }
set
{
if (value !=_CollapseMode)
{
eCollapseMode oldValue = _CollapseMode;
_CollapseMode = value;
OnCollapseModeChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when CollapseMode property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnCollapseModeChanged(eCollapseMode oldValue, eCollapseMode newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("CollapseMode"));
}
#endregion
}
/// <summary>
/// Defines available positions for buttons inside CollapsibleSplitterContainer.
/// </summary>
public enum eSplitterButtonPosition
{
/// <summary>
/// Buttons are positioned on left or top side depending on orientation.
/// </summary>
Near,
/// <summary>
/// Buttons are positioned in center of container.
/// </summary>
Center,
/// <summary>
/// Buttons are positioned on right or bottom side depending on orientation.
/// </summary>
Far,
}
/// <summary>
/// Defines collapse mode for the CollapsibleSplitContainer control.
/// </summary>
public enum eCollapseMode
{
/// <summary>
/// When buttons are pressed the splitter is positioned at the PanelMinSize.
/// </summary>
PanelMinSize,
/// <summary>
/// When buttons are pressed associated panel is collapsed through Panel1Collapsed or Panel2Collapsed properties.
/// </summary>
PanelCollapse
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,240 @@
using System;
using System.Text;
using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the color picker button control.
/// </summary>
[ToolboxBitmap(typeof(ColorPickerButton), "Controls.ColorPickerButton.ico"), ToolboxItem(true), DefaultEvent("SelectedColorChanged"), Designer("DevComponents.DotNetBar.Design.ColorPickerButtonDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf"), System.Runtime.InteropServices.ComVisible(false)]
public class ColorPickerButton : ButtonX
{
#region Private Variables
#endregion
#region Events
/// <summary>
/// Occurs when color is chosen from drop-down color picker or from Custom Colors dialog box. Selected color can be accessed through SelectedColor property.
/// </summary>
[Description("Occurs when color is chosen from drop-down color picker or from Custom Colors dialog box.")]
public event EventHandler SelectedColorChanged;
/// <summary>
/// Occurs when mouse is moving over the colors presented by the color picker. You can use it to preview the color before it is selected.
/// </summary>
[Description("Occurs when mouse is moving over the colors presented by the color picker")]
public event ColorPreviewEventHandler ColorPreview;
#endregion
#region Constructor
/// <summary>
/// Creates new instance of the object.
/// </summary>
public ColorPickerButton()
: base()
{
ColorPickerDropDown cp = GetColorPickerDropDown();
cp.SelectedColorChanged += new EventHandler(InternalSelectedColorChanged);
cp.ColorPreview += new ColorPreviewEventHandler(InternalColorPreview);
}
#endregion
#region Internal Implementation
#if FRAMEWORK20
/// <summary>
/// Gets or sets the array of ColorItem objects that will be used as standard colors instead of built-in color palette.
/// See: http://www.devcomponents.com/kb2/?p=79 for instructions.
/// </summary>
[DefaultValue(null), Browsable(false), Category("Colors"), Description("Array of ColorItem objects that will be used as standard colors instead of built-in color palette.")]
public ColorItem[][] CustomStandardColors
{
get { return GetColorPickerDropDown().CustomStandardColors; }
set
{
GetColorPickerDropDown().CustomStandardColors = value;
}
}
/// <summary>
/// Gets or sets the array of ColorItem objects that will be used as theme colors instead of built-in color palette.
/// See: http://www.devcomponents.com/kb2/?p=79 for instructions.
/// </summary>
[DefaultValue(null), Browsable(false), Category("Colors"), Description("Array of ColorItem objects that will be used as theme colors instead of built-in color palette.")]
public ColorItem[][] CustomThemeColors
{
get { return GetColorPickerDropDown().CustomThemeColors; }
set
{
GetColorPickerDropDown().CustomThemeColors = value;
}
}
#endif
/// <summary>
/// Displays the Colors dialog that allows user to choose the color or create a custom color. If new color is chosen the
/// SelectedColorChanged event is raised.
/// </summary>
public System.Windows.Forms.DialogResult DisplayMoreColorsDialog()
{
return GetColorPickerDropDown().DisplayMoreColorsDialog();
}
protected override ButtonItem CreateButtonItem()
{
return new ColorPickerDropDown();
}
private ColorPickerDropDown GetColorPickerDropDown()
{
return InternalItem as ColorPickerDropDown;
}
private void InternalColorPreview(object sender, ColorPreviewEventArgs e)
{
OnColorPreview(e);
}
/// <summary>
/// Raises the ColorPreview event.
/// </summary>
/// <param name="e">Provides event data.</param>
protected virtual void OnColorPreview(ColorPreviewEventArgs e)
{
if (ColorPreview != null)
ColorPreview(this, e);
}
private void InternalSelectedColorChanged(object sender, EventArgs e)
{
OnSelectedColorChanged(e);
ExecuteCommand();
}
/// <summary>
/// Gets whether command is executed when button is clicked.
/// </summary>
protected virtual bool ExecuteCommandOnClick
{
get { return false; }
}
/// <summary>
/// Raises the SelectedColorChanged event.
/// </summary>
/// <param name="e">Provides event data.</param>
protected virtual void OnSelectedColorChanged(EventArgs e)
{
if (SelectedColorChanged != null)
SelectedColorChanged(this, e);
}
/// <summary>
/// Gets or sets the Owner Window that will be used as owner for the colors modal dialog when displayed.
/// </summary>
[Browsable(false), DefaultValue(null)]
public System.Windows.Forms.IWin32Window OwnerWindow
{
get { return GetColorPickerDropDown().OwnerWindow; }
set { GetColorPickerDropDown().OwnerWindow = value; }
}
/// <summary>
/// Gets or sets more colors menu item is visible which allows user to open Custom Colors dialog box. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), DevCoSerialize(), Category("Appearance"), Description("Indicates more colors menu item is visible which allows user to open Custom Colors dialog box.")]
public bool DisplayMoreColors
{
get { return GetColorPickerDropDown().DisplayMoreColors; }
set { GetColorPickerDropDown().DisplayMoreColors = value; }
}
/// <summary>
/// Gets or sets the last selected color from either the drop-down or Custom Color dialog box. Default value is
/// Color.Empty. You can use SelectedColorChanged event to be notified when this property changes.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Color SelectedColor
{
get { return GetColorPickerDropDown().SelectedColor; }
set { GetColorPickerDropDown().SelectedColor = value; }
}
/// <summary>
/// Gets or sets whether theme colors are displayed on drop-down. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), DevCoSerialize(), Category("Appearance"), Description("Indicates whether theme colors are displayed on drop-down.")]
public bool DisplayThemeColors
{
get { return GetColorPickerDropDown().DisplayThemeColors; }
set { GetColorPickerDropDown().DisplayThemeColors = value; }
}
/// <summary>
/// Gets or sets whether standard colors are displayed on drop-down. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), DevCoSerialize(), Category("Appearance"), Description("Indicates whether standard colors are displayed on drop-down.")]
public bool DisplayStandardColors
{
get { return GetColorPickerDropDown().DisplayStandardColors; }
set { GetColorPickerDropDown().DisplayStandardColors = value; }
}
/// <summary>
/// Indicates whether SubItems collection is serialized. ColorPickerDropDown does not serialize the sub items.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSubItems()
{
return false;
}
/// <summary>
/// Gets or sets the rectangle in Image coordinates where selected color will be painted. Setting this property will
/// have an effect only if Image property is used to set the image. Default value is an empty rectangle which indicates
/// that selected color will not be painted on the image.
/// </summary>
[Browsable(true), Description("Indicates rectangle in Image coordinates where selected color will be painted. Property will have effect only if Image property is used to set the image."), Category("Behaviour")]
public Rectangle SelectedColorImageRectangle
{
get { return GetColorPickerDropDown().SelectedColorImageRectangle; }
set { GetColorPickerDropDown().SelectedColorImageRectangle = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSelectedColorImageRectangle()
{
return GetColorPickerDropDown().ShouldSerializeSelectedColorImageRectangle();
}
/// <summary>
/// Resets the property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSelectedColorImageRectangle()
{
GetColorPickerDropDown().ResetSelectedColorImageRectangle();
}
/// <summary>
/// Invokes the ColorPreview event.
/// </summary>
/// <param name="e">Provides data for the event.</param>
public void InvokeColorPreview(ColorPreviewEventArgs e)
{
GetColorPickerDropDown().InvokeColorPreview(e);
}
/// <summary>
/// Update the selected color image if the SelectedColorImageRectangle has been set and button is using Image property to display the image.
/// </summary>
public void UpdateSelectedColorImage()
{
GetColorPickerDropDown().UpdateSelectedColorImage();
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,156 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false)]
public class ControlWithBackgroundStyle : Control
{
#region Private Variables
private ElementStyle _BackgroundStyle = null;
private bool _AntiAlias = true;
#endregion
#region Events
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the ControlWithBackgroundStyle class.
/// </summary>
public ControlWithBackgroundStyle()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.StandardDoubleClick, true);
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
_BackgroundStyle = new ElementStyle();
_BackgroundStyle.StyleChanged += new EventHandler(this.VisualPropertyChanged);
}
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets whether anti-alias smoothing is used while painting. Default value is true.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Gets or sets whether anti-aliasing is used while painting.")]
public virtual bool AntiAlias
{
get { return _AntiAlias; }
set
{
if (_AntiAlias != value)
{
_AntiAlias = value;
this.Invalidate();
}
}
}
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Category("Style"), Description("Indicates control background style."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return _BackgroundStyle; }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
_BackgroundStyle.StyleChanged -= new EventHandler(this.VisualPropertyChanged);
_BackgroundStyle = new ElementStyle();
_BackgroundStyle.StyleChanged += new EventHandler(this.VisualPropertyChanged);
this.Invalidate();
}
private void VisualPropertyChanged(object sender, EventArgs e)
{
OnVisualPropertyChanged();
}
protected virtual void OnVisualPropertyChanged()
{
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.BackColor.IsEmpty || this.BackColor == Color.Transparent)
{
base.OnPaintBackground(e);
}
PaintBackground(e);
PaintContent(e);
base.OnPaint(e);
}
protected virtual void PaintContent(PaintEventArgs e)
{
}
protected virtual Rectangle GetContentRectangle()
{
bool disposeStyle = false;
ElementStyle style = this.GetBackgroundStyle(out disposeStyle);
Rectangle r = ElementStyleLayout.GetInnerRect(style, this.ClientRectangle);
if (disposeStyle) style.Dispose();
//Rectangle r=this.ClientRectangle;
//r.X += ElementStyleLayout.LeftWhiteSpace(style);
//r.Y += ElementStyleLayout.TopWhiteSpace(style);
//r.Width -= ElementStyleLayout.HorizontalStyleWhiteSpace(style);
//r.Height -= ElementStyleLayout.VerticalStyleWhiteSpace(style);
return r;
}
protected virtual ElementStyle GetBackgroundStyle(out bool disposeStyle)
{
disposeStyle = false;
return ElementStyleDisplay.GetElementStyle(_BackgroundStyle, out disposeStyle);
}
protected virtual void PaintBackground(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle r = this.ClientRectangle;
bool disposeStyle = false;
ElementStyle style = this.GetBackgroundStyle(out disposeStyle);
if (!this.BackColor.IsEmpty)
{
DisplayHelp.FillRectangle(g, r, this.BackColor);
}
if (style.Custom)
{
SmoothingMode sm = g.SmoothingMode;
if (this.AntiAlias)
g.SmoothingMode = SmoothingMode.HighQuality;
ElementStyleDisplayInfo displayInfo = new ElementStyleDisplayInfo(style, e.Graphics, r);
ElementStyleDisplay.Paint(displayInfo);
if (this.AntiAlias)
g.SmoothingMode = sm;
}
if (disposeStyle) style.Dispose();
}
#endregion
}
}

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
internal struct IconInfo
{
public bool fIcon;
public int xHotspot;
public int yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}
internal class CursorHelper
{
[DllImport("user32.dll")]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr handle);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);
public static Cursor CreateCursor(Bitmap bm, int xHotspot, int yHotspot, bool resize = true)
{
IntPtr ptr = (resize) ? ((Bitmap)ResizeBitmap(bm, 32, 32)).GetHicon() : bm.GetHicon();
IconInfo inf = new IconInfo();
GetIconInfo(ptr, ref inf);
inf.xHotspot = xHotspot;
inf.yHotspot = yHotspot;
inf.fIcon = false;
IntPtr cursorPtr = CreateIconIndirect(ref inf);
if (inf.hbmColor != IntPtr.Zero) { DeleteObject(inf.hbmColor); }
if (inf.hbmMask != IntPtr.Zero) { DeleteObject(inf.hbmMask); }
if (ptr != IntPtr.Zero) { DestroyIcon(ptr); }
Cursor c = new Cursor(cursorPtr);
c.Tag = (resize) ? new Size(32, 32) : bm.Size;
return c;
}
public static Bitmap ResizeBitmap(Image image, int maxWidth, int maxHeight)
{
double ratio = System.Math.Min((double)maxHeight / image.Height, (double)maxWidth / image.Width);
var propWidth = (int)(image.Width * ratio);
var propHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(propWidth, propHeight);
using (var g = Graphics.FromImage(newImage))
{
g.DrawImage(image, 0, 0, propWidth, propHeight);
}
return newImage;
}
public static Bitmap GetControlBitmap(Control c, Color transparent)
{
var bm = new Bitmap(c.Width, c.Height);
c.DrawToBitmap(bm, new Rectangle(0, 0, c.Width, c.Height));
if (!transparent.IsEmpty)
{
bm.MakeTransparent(transparent);
}
return bm;
}
public static Bitmap OverlayBitmap(Bitmap baseBitmap, Bitmap overlay, Point atPosition)
{
using (var g = Graphics.FromImage(baseBitmap))
{
g.DrawImage(overlay, new Rectangle(atPosition, overlay.Size));
}
return baseBitmap;
}
}
}

View File

@@ -0,0 +1,196 @@
#if FRAMEWORK20
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using DevComponents.DotNetBar.ScrollBar;
using System.ComponentModel;
using DevComponents.DotNetBar.Rendering;
using System.Runtime.InteropServices;
using System.Reflection;
namespace DevComponents.DotNetBar.Controls
{
internal class DGHScrollBar : HScrollBar, ScrollBarReplacement.IScrollBarExtender
{
#region Private Variables
private ScrollBarReplacement m_ScrollBarImpl = null;
private bool m_EnableStyling = true;
#endregion
#region Constructor
public DGHScrollBar()
{
m_ScrollBarImpl = new ScrollBarReplacement(this);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
}
#endregion
#region Internal Implementation
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
if (m_EnableStyling)
{
p.ClassName = null;
p.Style = 0x2000000;
p.Style |= 0x44000000;
if (this.Visible)
p.Style |= 0x10000000;
if (!this.Enabled)
p.Style |= 0x8000000;
if (this.RightToLeft == RightToLeft.Yes)
{
p.ExStyle |= 0x2000;
p.ExStyle |= 0x1000;
p.ExStyle |= 0x4000;
}
}
return p;
}
}
protected override void Dispose(bool disposing)
{
m_ScrollBarImpl.Dispose();
base.Dispose(disposing);
}
/// <summary>
/// Gets or sets whether custom styling (Office 2007 style) is enabled. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether custom styling (Office 2007 style) is enabled.")]
public bool EnableStyling
{
get { return m_EnableStyling; }
set
{
if (m_EnableStyling != value)
{
m_EnableStyling = value;
if (this.IsHandleCreated)
this.RecreateHandle();
}
}
}
///// <summary>
///// Gets or sets whether scroll bar appears as application style scroll bar which usually uses darker colors. Default value is true.
///// </summary>
//[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether scroll bar appears as application style scroll bar which usually uses darker colors.")]
//public bool IsAppScrollBarStyle
//{
// get { return m_ScrollBarImpl.IsAppScrollBarStyle; }
// set { m_ScrollBarImpl.IsAppScrollBarStyle = value; }
//}
protected override void OnHandleCreated(EventArgs e)
{
m_ScrollBarImpl.OnHandleCreated();
base.OnHandleCreated(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseDown(e);
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseUp(e);
base.OnMouseUp(e);
}
protected override void OnMouseEnter(EventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseEnter(e);
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseLeave(e);
base.OnMouseLeave(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseMove(e);
base.OnMouseMove(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if(m_EnableStyling)
m_ScrollBarImpl.OnPaint(e);
base.OnPaint(e);
}
protected override void NotifyInvalidate(Rectangle invalidatedArea)
{
if (m_EnableStyling)
m_ScrollBarImpl.NotifyInvalidate(invalidatedArea);
base.NotifyInvalidate(invalidatedArea);
}
public void UpdateScrollValues()
{
m_ScrollBarImpl.UpdateScrollValues();
}
protected override void OnParentChanged(EventArgs e)
{
if (this.Parent is DataGridView)
{
m_ScrollBarImpl.ScrollBarCore.SideBorderOnly = true;
m_ScrollBarImpl.ScrollBarCore.HasBorder = false;
}
else
{
m_ScrollBarImpl.ScrollBarCore.SideBorderOnly = false;
m_ScrollBarImpl.ScrollBarCore.HasBorder = true;
}
base.OnParentChanged(e);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
UpdateScrollValues();
}
public bool AppStyleScrollBar
{
get { return m_ScrollBarImpl.AppStyleScrollBar; }
set { m_ScrollBarImpl.AppStyleScrollBar = value; }
}
#endregion
#region IScrollBarExtender Members
void ScrollBarReplacement.IScrollBarExtender.SetValue(int newValue, ScrollEventType type)
{
if (newValue != this.Value)
{
int v = this.Value;
this.Value = newValue;
ScrollEventArgs se = new ScrollEventArgs(type, v, newValue, ScrollOrientation.HorizontalScroll);
OnScroll(se);
}
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,206 @@
#if FRAMEWORK20
using System;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents the Vertical Office 2007 Style Scroll Bar control.
/// </summary>
internal class DGVScrollBar : VScrollBar, ScrollBarReplacement.IScrollBarExtender
{
#region Private Variables
private ScrollBarReplacement m_ScrollBarImpl = null;
private bool m_EnableStyling = true;
#endregion
#region Constructor
public DGVScrollBar()
{
m_ScrollBarImpl = new ScrollBarReplacement(this);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, false);
}
#endregion
#region Internal Implementation
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
if (m_EnableStyling)
{
p.ClassName = null;
p.Style = 0x2000000;
p.Style |= 0x44000000;
if (this.Visible)
p.Style |= 0x10000000;
if (!this.Enabled)
p.Style |= 0x8000000;
if (this.RightToLeft == RightToLeft.Yes)
{
p.ExStyle |= 0x2000;
p.ExStyle |= 0x1000;
p.ExStyle |= 0x4000;
}
}
return p;
}
}
protected override void Dispose(bool disposing)
{
m_ScrollBarImpl.Dispose();
base.Dispose(disposing);
}
/// <summary>
/// Gets or sets whether custom styling (Office 2007 style) is enabled. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether custom styling (Office 2007 style) is enabled.")]
public bool EnableStyling
{
get { return m_EnableStyling; }
set
{
if (m_EnableStyling != value)
{
m_EnableStyling = value;
if (this.IsHandleCreated)
this.RecreateHandle();
}
}
}
///// <summary>
///// Gets or sets whether scroll bar appears as application style scroll bar which usually uses darker colors. Default value is true.
///// </summary>
//[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether scroll bar appears as application style scroll bar which usually uses darker colors.")]
//public bool IsAppScrollBarStyle
//{
// get { return m_ScrollBarImpl.IsAppScrollBarStyle; }
// set { m_ScrollBarImpl.IsAppScrollBarStyle = value; }
//}
protected override void OnHandleCreated(EventArgs e)
{
m_ScrollBarImpl.OnHandleCreated();
base.OnHandleCreated(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseDown(e);
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseUp(e);
base.OnMouseUp(e);
}
protected override void OnMouseEnter(EventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseEnter(e);
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
if (m_EnableStyling)
m_ScrollBarImpl.OnMouseLeave(e);
base.OnMouseLeave(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (m_EnableStyling)
{
m_ScrollBarImpl.UpdateScrollValues();
m_ScrollBarImpl.OnMouseMove(e);
}
base.OnMouseMove(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if(m_EnableStyling)
m_ScrollBarImpl.OnPaint(e);
base.OnPaint(e);
}
protected override void NotifyInvalidate(Rectangle invalidatedArea)
{
if (m_EnableStyling)
m_ScrollBarImpl.NotifyInvalidate(invalidatedArea);
base.NotifyInvalidate(invalidatedArea);
}
protected override void OnResize(EventArgs e)
{
UpdateScrollValues();
base.OnResize(e);
}
public void UpdateScrollValues()
{
m_ScrollBarImpl.UpdateScrollValues();
}
protected override void OnParentChanged(EventArgs e)
{
if (this.Parent is DataGridView)
{
m_ScrollBarImpl.ScrollBarCore.SideBorderOnly = true;
m_ScrollBarImpl.ScrollBarCore.HasBorder = false;
}
else
{
m_ScrollBarImpl.ScrollBarCore.SideBorderOnly = false;
m_ScrollBarImpl.ScrollBarCore.HasBorder = true;
}
base.OnParentChanged(e);
}
public bool AppStyleScrollBar
{
get { return m_ScrollBarImpl.AppStyleScrollBar; }
set { m_ScrollBarImpl.AppStyleScrollBar = value; }
}
#endregion
#region IScrollBarExtender Members
void ScrollBarReplacement.IScrollBarExtender.SetValue(int newValue, ScrollEventType type)
{
//if (newValue != this.Value)
{
// Fix for scrolling to the last row
if (type== ScrollEventType.SmallIncrement &&
(this.Maximum - this.LargeChange) - newValue < 21)
{
newValue = this.Maximum - this.LargeChange + 1;
type = ScrollEventType.Last;
}
int v = this.Value;
this.Value = newValue;
ScrollEventArgs se = new ScrollEventArgs(type, v, newValue, ScrollOrientation.VerticalScroll);
OnScroll(se);
}
}
#endregion
}
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 568 B

View File

@@ -0,0 +1,812 @@
#if FRAMEWORK20
using System;
using System.Windows.Forms;
using System.Drawing;
using DevComponents.DotNetBar.Rendering;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.ComponentModel;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents the DataGridView control with enhanced Office 2007 style.
/// </summary>
[ToolboxBitmap(typeof(DataGridViewX), "Controls.DataGridViewX.bmp")]
public class DataGridViewX : DataGridView
{
#region Private Variables
private int m_MouseOverColumnHeader = -2;
private int m_MouseDownColumnHeader = -2;
private int m_MouseDownRowIndex = -2;
private int m_MouseOverRowIndex = -2;
private bool m_Office2007StyleEnabled = true;
private Office2007DataGridViewColorTable m_ColorTable = null;
private Office2007ButtonItemStateColorTable m_ButtonStateColorTable = null;
private SelectionInfo[] m_ColumnSelectionState = new SelectionInfo[1];
//private int m_CurrentCellRowIndex = -1;
private int m_SelectedRowIndex = -2;
private bool m_HighlightSelectedColumnHeaders = true;
private bool m_SelectAllSignVisible = true;
private bool m_PaintEnhancedSelection = true;
#endregion
#region Constructor
public DataGridViewX()
: base()
{
SetupScrollBars();
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw, true);
this.DoubleBuffered = true;
StyleManager.Register(this);
}
#endregion
#region internal properties
internal Office2007ButtonItemStateColorTable ButtonStateColorTable
{
get { return (m_ButtonStateColorTable); }
}
#endregion
#region Internal Implementation
/// <summary>
/// Called by StyleManager to notify control that style on manager has changed and that control should refresh its appearance if
/// its style is controlled by StyleManager.
/// </summary>
/// <param name="newStyle">New active style.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void StyleManagerStyleChanged(eDotNetBarStyle newStyle)
{
DGVScrollBar vsb = GetVScrollBar();
if (vsb != null && vsb.Visible) vsb.Invalidate();
DGHScrollBar hsb = GetHScrollBar();
if (hsb != null && hsb.Visible) hsb.Invalidate();
// Update Style
Office2007ColorTable ct = null;
if (GlobalManager.Renderer is Office2007Renderer)
{
ct = ((Office2007Renderer)GlobalManager.Renderer).ColorTable;
m_ColorTable = ct.DataGridView;
m_ButtonStateColorTable = ct.ButtonItemColors[0].Checked;
}
try // Don't like to do this but bug in GridColor setter requires it
{
if (!_UseCustomBackgroundColor)
this.BackgroundColor = m_ColorTable.BackgroundColor;
this.ColumnHeadersDefaultCellStyle.ForeColor = m_ColorTable.ColumnHeaderNormalText;
this.ColumnHeadersDefaultCellStyle.SelectionForeColor = m_ColorTable.ColumnHeaderSelectedText;
this.DefaultCellStyle.BackColor = m_ColorTable.DefaultCellBackground;
this.DefaultCellStyle.ForeColor = m_ColorTable.DefaultCellText;
if (this.PaintEnhancedSelection)
this.DefaultCellStyle.SelectionForeColor = m_ButtonStateColorTable.Text;
this.GridColor = m_ColorTable.GridColor;
this.RowHeadersDefaultCellStyle.ForeColor = m_ColorTable.ColumnHeaderNormalText;
this.RowHeadersDefaultCellStyle.SelectionForeColor = m_ColorTable.ColumnHeaderSelectedText;
this.EnableHeadersVisualStyles = false;
}
catch { }
}
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
bool enabled = this.Enabled;
Office2007DataGridViewColorTable ct = GetColorTable();
if (!m_Office2007StyleEnabled || ct == null ||
e.Handled || e.ColumnIndex >= 0 && e.RowIndex >= 0 &&
(!m_PaintEnhancedSelection || (e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected))
{
base.OnCellPainting(e);
return;
}
Rectangle r = e.CellBounds;
Graphics g = e.Graphics;
LinearGradientColorTable bt = null;
Color borderColor = Color.Empty;
DataGridViewColumn column = null;
int displayIndex = -1;
if (e.ColumnIndex >= 0)
{
column = this.Columns[e.ColumnIndex];
displayIndex = column.DisplayIndex;
}
if (e.ColumnIndex == -1 && e.RowIndex == -1)
{
// Paint top-left corner
if (m_MouseOverColumnHeader == -1)
{
bt = ct.SelectorMouseOverBackground;
borderColor = ct.SelectorMouseOverBorder;
}
else
{
bt = ct.SelectorBackground;
borderColor = ct.SelectorBorder;
}
DisplayHelp.FillRectangle(g, r, bt);
DisplayHelp.DrawRectangle(g, borderColor, r);
if (m_MouseOverColumnHeader == -1)
borderColor = ct.SelectorMouseOverBorderLight;
else
borderColor = ct.SelectorBorderLight;
Rectangle inner = r;
inner.Inflate(-1, -1);
using (Pen p = new Pen(borderColor))
{
g.DrawLine(p, inner.X, inner.Bottom - 1, inner.X, inner.Y);
g.DrawLine(p, inner.X, inner.Y, inner.Right - 1, inner.Y);
}
if (m_MouseOverColumnHeader == -1)
borderColor = ct.SelectorMouseOverBorderDark;
else
borderColor = ct.SelectorBorderDark;
using (Pen p = new Pen(borderColor))
{
g.DrawLine(p, inner.Right - 1, inner.Y, inner.Right - 1, inner.Bottom - 1);
g.DrawLine(p, inner.X, inner.Bottom - 1, inner.Right - 1, inner.Bottom - 1);
}
if (m_SelectAllSignVisible)
{
GraphicsPath path = GetSelectorPath(inner);
if (path != null)
{
DisplayHelp.FillPath(g, path, (m_MouseOverColumnHeader == -1 ? ct.SelectorMouseOverSign : ct.SelectorSign));
path.Dispose();
}
}
}
else if (e.ColumnIndex == -1)
{
// Paint Rows
bt = ct.RowNormalBackground;
borderColor = ct.RowNormalBorder;
if (m_MouseDownRowIndex == e.RowIndex)
{
bt = ct.RowPressedBackground;
borderColor = ct.RowPressedBorder;
}
else if (m_SelectedRowIndex == e.RowIndex && enabled)
{
if (m_MouseOverRowIndex == e.RowIndex)
{
bt = ct.RowSelectedMouseOverBackground;
borderColor = ct.RowSelectedMouseOverBorder;
}
else
{
bt = ct.RowSelectedBackground;
borderColor = ct.RowSelectedBorder;
}
}
else if (this.Rows[e.RowIndex].Selected && enabled)
{
if (m_MouseOverRowIndex == e.RowIndex)
{
bt = ct.RowPressedBackground;
borderColor = ct.RowPressedBorder;
}
else
{
bt = ct.RowPressedBackground;
borderColor = ct.RowPressedBorder;
}
}
else if (m_MouseOverRowIndex == e.RowIndex)
{
bt = ct.RowMouseOverBackground;
borderColor = ct.RowMouseOverBorder;
}
DisplayHelp.FillRectangle(g, r, bt);
// Paint border
using (Pen p = new Pen(borderColor))
{
g.DrawLine(p, r.Right - 1, r.Y, r.Right - 1, r.Bottom - 1);
if (m_SelectedRowIndex == e.RowIndex + 1 && enabled)
{
Color bc = ct.RowSelectedBorder;
if (m_MouseDownRowIndex == e.RowIndex + 1)
bc = ct.RowPressedBorder;
else if (m_MouseOverRowIndex == e.RowIndex + 1)
bc = ct.RowSelectedMouseOverBorder;
using (Pen p2 = new Pen(bc))
g.DrawLine(p2, r.X, r.Bottom - 1, r.Right - 1, r.Bottom - 1);
}
else
g.DrawLine(p, r.X, r.Bottom - 1, r.Right - 1, r.Bottom - 1);
}
e.PaintContent(r);
}
else if (e.RowIndex == -1)
{
// Determine Colors
if (m_MouseDownColumnHeader == e.ColumnIndex)
{
bt = ct.ColumnHeaderPressedBackground;
borderColor = ct.ColumnHeaderPressedBorder;
}
else if (m_MouseOverColumnHeader == e.ColumnIndex)
{
if (m_HighlightSelectedColumnHeaders && (displayIndex >= 0 && e.ColumnIndex >= 0 && (m_ColumnSelectionState.Length > displayIndex && m_ColumnSelectionState[displayIndex].Selected || this.Columns[e.ColumnIndex].Selected)))
{
bt = ct.ColumnHeaderSelectedMouseOverBackground;
borderColor = ct.ColumnHeaderSelectedMouseOverBorder;
}
else
{
bt = ct.ColumnHeaderMouseOverBackground;
borderColor = ct.ColumnHeaderMouseOverBorder;
}
}
else if (!m_HighlightSelectedColumnHeaders)
{
bt = ct.ColumnHeaderNormalBackground;
borderColor = ct.ColumnHeaderNormalBorder;
}
else if (displayIndex >= 0 && e.ColumnIndex >= 0 && (m_ColumnSelectionState.Length > displayIndex && m_ColumnSelectionState[displayIndex].Selected || this.Columns[e.ColumnIndex].Selected) && enabled)
{
bt = ct.ColumnHeaderSelectedBackground;
borderColor = ct.ColumnHeaderSelectedBorder;
}
else
{
if (this.Columns[e.ColumnIndex].Selected && enabled)
{
bt = ct.ColumnHeaderPressedBackground;
borderColor = ct.ColumnHeaderPressedBorder;
}
else
{
bt = ct.ColumnHeaderNormalBackground;
borderColor = ct.ColumnHeaderNormalBorder;
}
}
// Paint row markers
DisplayHelp.FillRectangle(g, r, bt);
// Paint border
using (Pen p = new Pen(borderColor))
{
g.DrawLine(p, r.X, r.Bottom-1, r.Right - 1, r.Bottom-1);
//if (displayIndex == 0)
// g.DrawLine(p, r.X, r.Y, r.X, r.Bottom - 1);
if (enabled && (m_HighlightSelectedColumnHeaders && (displayIndex>=0 && m_ColumnSelectionState.Length > displayIndex + 1 && (m_ColumnSelectionState[displayIndex + 1].Selected ||
m_ColumnSelectionState[displayIndex + 1].ColumnIndex == m_MouseDownColumnHeader))))
{
Color bc = ct.ColumnHeaderSelectedBorder;
if (m_ColumnSelectionState[displayIndex + 1].ColumnIndex == m_MouseDownColumnHeader)
bc = ct.ColumnHeaderPressedBorder;
else if (m_MouseOverColumnHeader == displayIndex + 1)
bc = ct.ColumnHeaderSelectedMouseOverBorder;
using (Pen p2 = new Pen(bc))
g.DrawLine(p2, r.Right - 1, r.Y, r.Right - 1, r.Bottom - 1);
}
else
g.DrawLine(p, r.Right - 1, r.Y, r.Right - 1, r.Bottom - 1);
}
e.PaintContent(r);
}
else if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected)
{
IDataGridViewColumn ic = this.Columns[e.ColumnIndex] as IDataGridViewColumn;
if (ic != null && ic.OwnerPaintCell == true)
{
base.OnCellPainting(e);
return;
}
e.PaintBackground(r, false);
if (enabled)
{
r.Height--;
Office2007ButtonItemPainter.PaintBackground(g, m_ButtonStateColorTable, r, RoundRectangleShapeDescriptor.RectangleShape, false, false);
r.Height++;
if (CurrentCellAddress.X==e.ColumnIndex && CurrentCellAddress.Y==e.RowIndex && (e.PaintParts & DataGridViewPaintParts.Focus) == DataGridViewPaintParts.Focus &&
ShowFocusCues && Focused && r.Width > 0 && r.Height > 0)
{
if (m_ButtonStateColorTable.TopBackground != null)
ControlPaint.DrawFocusRectangle(g, r, Color.Empty, m_ButtonStateColorTable.TopBackground.End);
else if (m_ButtonStateColorTable.Background != null)
ControlPaint.DrawFocusRectangle(g, r, Color.Empty, m_ButtonStateColorTable.Background.Start);
else
ControlPaint.DrawFocusRectangle(g, r, Color.Empty, this.BackgroundColor);
}
}
e.PaintContent(r);
}
e.Handled = true;
base.OnCellPainting(e);
}
private GraphicsPath GetSelectorPath(Rectangle inner)
{
inner.Inflate(-3, -3);
if (inner.Width > 2 && inner.Height > 2)
{
GraphicsPath path = new GraphicsPath();
path.AddLine(inner.Right, inner.Y, inner.Right, inner.Bottom);
path.AddLine(inner.Right, inner.Bottom, inner.Right - inner.Height, inner.Bottom);
path.CloseAllFigures();
return path;
}
return null;
}
protected override void OnHandleCreated(EventArgs e)
{
if (GlobalManager.Renderer is Office2007Renderer)
{
Office2007DataGridViewColorTable ct = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.DataGridView;
UpdateOffice2007Styles(ct);
}
base.OnHandleCreated(e);
}
private void UpdateOffice2007Styles(Office2007DataGridViewColorTable ct)
{
if (this.GridColor != ct.GridColor)
this.GridColor = ct.GridColor;
if(m_PaintEnhancedSelection)
this.DefaultCellStyle.SelectionForeColor = this.DefaultCellStyle.ForeColor;
}
protected override void OnPaint(PaintEventArgs e)
{
Office2007ColorTable ct = null;
if (GlobalManager.Renderer is Office2007Renderer)
{
ct = ((Office2007Renderer)GlobalManager.Renderer).ColorTable;
m_ColorTable = ct.DataGridView;
if(StyleManager.IsVisualStudio2012(StyleManager.Style))
m_ButtonStateColorTable = ct.ButtonItemColors[0].Pressed;
else
m_ButtonStateColorTable = ct.ButtonItemColors[0].Checked;
}
if (this.CurrentCell != null)
m_SelectedRowIndex = this.CurrentCell.RowIndex;
else
m_SelectedRowIndex = -1;
base.OnPaint(e);
if (this.VerticalScrollBar.Visible && this.HorizontalScrollBar.Visible)
{
Rectangle r = new Rectangle(this.VerticalScrollBar.Left, this.VerticalScrollBar.Bottom, this.VerticalScrollBar.Width, this.HorizontalScrollBar.Height);
Color c = ct.AppScrollBar.Default.Background.End;
if (c.IsEmpty) c = ct.AppScrollBar.Default.Background.Start;
DisplayHelp.FillRectangle(e.Graphics, r, c);
//e.Graphics.FillRectangle(Brushes.BlueViolet, r);
}
m_ColorTable = null;
m_ButtonStateColorTable = null;
}
protected override void OnCurrentCellChanged(EventArgs e)
{
if (this.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
UpdateSelectionState();
base.OnCurrentCellChanged(e);
}
protected override void OnSelectionChanged(EventArgs e)
{
UpdateSelectionState();
base.OnSelectionChanged(e);
}
protected override void OnDataSourceChanged(EventArgs e)
{
base.OnDataSourceChanged(e);
UpdateSelectionState();
}
private void UpdateSelectionState()
{
SelectionInfo[] newSelection = new SelectionInfo[this.Columns.Count];
for (int i = 0; i < this.Columns.Count; i++)
newSelection[this.Columns[i].DisplayIndex].ColumnIndex = i;
int columnCount = this.Columns.Count;
if (this.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
{
if (this.CurrentCell != null)
{
int displayIndex = this.Columns[this.CurrentCell.ColumnIndex].DisplayIndex;
newSelection[displayIndex].Selected = true;
newSelection[displayIndex].ColumnIndex = this.CurrentCell.ColumnIndex;
}
}
else
{
foreach (DataGridViewCell cell in this.SelectedCells)
{
if (cell.ColumnIndex == -1) continue;
int displayIndex = this.Columns[cell.ColumnIndex].DisplayIndex;
if (!newSelection[displayIndex].Selected)
{
columnCount--;
newSelection[displayIndex].Selected = true;
newSelection[displayIndex].ColumnIndex = cell.ColumnIndex;
if (columnCount == 0) break;
}
}
}
for (int i = 0; i < newSelection.Length; i++)
{
if (m_ColumnSelectionState.Length > i && newSelection[i].Selected != m_ColumnSelectionState[i].Selected)
{
int ci = m_ColumnSelectionState[i].ColumnIndex;
if (!(ci < 0 || ci >= this.Columns.Count))
{
this.InvalidateColumn(ci);
if (ci > 0) this.InvalidateColumn(ci - 1);
}
}
}
if (m_SelectedRowIndex > 0 && m_SelectedRowIndex < this.Rows.Count)
this.InvalidateRow(m_SelectedRowIndex - 1);
if (this.CurrentCell != null && this.CurrentCell.RowIndex > 0)
{
m_SelectedRowIndex = this.CurrentCell.RowIndex;
this.InvalidateRow(m_SelectedRowIndex - 1);
}
else
m_SelectedRowIndex = -2;
m_ColumnSelectionState = newSelection;
}
protected virtual Office2007DataGridViewColorTable GetColorTable()
{
return m_ColorTable;
}
protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e)
{
// Disable double buffer so column resize drag markers will work
if (e.ColumnIndex == -1 || e.RowIndex == -1)
{
this.DoubleBuffered = false;
}
if (e.RowIndex == -1)
{
m_MouseDownColumnHeader = e.ColumnIndex;
if (e.ColumnIndex >= 0)
this.InvalidatePreviousColumn(this.Columns[e.ColumnIndex].DisplayIndex);
}
else
m_MouseDownColumnHeader = -2;
if (e.ColumnIndex == -1)
{
m_MouseDownRowIndex = e.RowIndex;
if (m_MouseDownRowIndex > 0 && m_MouseDownRowIndex < this.Rows.Count)
this.InvalidateRow(m_MouseDownRowIndex - 1);
}
else
m_MouseDownRowIndex = -2;
base.OnCellMouseDown(e);
}
private void InvalidatePreviousColumn(int displayIndex)
{
displayIndex--;
for (int i = 0; i < this.Columns.Count; i++)
{
DataGridViewColumn c = this.Columns[i];
if (c.Displayed && c.DisplayIndex == displayIndex)
{
this.InvalidateColumn(i);
break;
}
}
}
protected override void OnDragDrop(DragEventArgs drgevent)
{
CleanUpOnCellMouseUp();
base.OnDragDrop(drgevent);
}
private void CleanUpOnCellMouseUp()
{
// Enable double buffering that was disabled in CellMouseDown
if (!this.DoubleBuffered)
this.DoubleBuffered = true;
if (m_MouseDownRowIndex > 0 && m_MouseDownRowIndex < this.Rows.Count)
this.InvalidateRow(m_MouseDownRowIndex - 1);
if (m_MouseDownRowIndex >= 0 && m_MouseDownRowIndex < this.Rows.Count)
this.InvalidateRow(m_MouseDownRowIndex);
m_MouseDownRowIndex = -2;
m_MouseDownColumnHeader = -2;
}
protected override void OnCellMouseUp(DataGridViewCellMouseEventArgs e)
{
CleanUpOnCellMouseUp();
base.OnCellMouseUp(e);
}
protected override void OnCellMouseEnter(DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1)
m_MouseOverColumnHeader = e.ColumnIndex;
else
m_MouseOverColumnHeader = -2;
if (e.ColumnIndex == -1)
{
if (m_MouseOverRowIndex != e.RowIndex)
{
m_MouseOverRowIndex = e.RowIndex;
if (m_MouseOverRowIndex > 0)
this.InvalidateRow(m_MouseOverRowIndex - 1);
}
}
else
m_MouseOverRowIndex = -2;
base.OnCellMouseEnter(e);
}
protected override void OnCellMouseLeave(DataGridViewCellEventArgs e)
{
m_MouseOverColumnHeader = -2;
m_MouseOverRowIndex = -2;
base.OnCellMouseLeave(e);
}
private struct SelectionInfo
{
public bool Selected;
public int ColumnIndex;
}
protected override void OnScroll(ScrollEventArgs e)
{
base.OnScroll(e);
DGVScrollBar vsb = GetVScrollBar();
if (vsb != null && vsb.Visible) vsb.UpdateScrollValues();
DGHScrollBar hsb = GetHScrollBar();
if (hsb != null && hsb.Visible) hsb.UpdateScrollValues();
}
private DGVScrollBar GetVScrollBar()
{
return this.VerticalScrollBar as DGVScrollBar;
//Type t = typeof(System.Windows.Forms.DataGridView);
//FieldInfo fi = t.GetField("vertScrollBar", BindingFlags.NonPublic | BindingFlags.Instance);
//if (fi == null) return null;
//DGVScrollBar sb = fi.GetValue(this) as DGVScrollBar;
//return sb;
}
private DGHScrollBar GetHScrollBar()
{
return this.HorizontalScrollBar as DGHScrollBar;
//Type t = typeof(System.Windows.Forms.DataGridView);
//FieldInfo fi = t.GetField("horizScrollBar", BindingFlags.NonPublic | BindingFlags.Instance);
//if (fi == null) return null;
//DGHScrollBar sb = fi.GetValue(this) as DGHScrollBar;
//return sb;
}
private void InvokeDelayed(MethodInvoker method)
{
Timer delayedInvokeTimer = new Timer();
delayedInvokeTimer = new Timer();
delayedInvokeTimer.Tag = method;
delayedInvokeTimer.Interval = 10;
delayedInvokeTimer.Tick += new EventHandler(DelayedInvokeTimerTick);
delayedInvokeTimer.Start();
}
void DelayedInvokeTimerTick(object sender, EventArgs e)
{
Timer timer = (Timer)sender;
MethodInvoker method = (MethodInvoker)timer.Tag;
timer.Stop();
timer.Dispose();
method.Invoke();
}
protected override void OnResize(EventArgs e)
{
if (_DelayResizeCallWhenMdiChild)
{
Form form = this.FindForm();
if (form != null && form.IsMdiChild)
InvokeDelayed(new MethodInvoker(delegate { CallBaseOnResize(e); }));
else
base.OnResize(e);
}
else
base.OnResize(e);
}
private void CallBaseOnResize(EventArgs e)
{
base.OnResize(e);
}
private bool _DelayResizeCallWhenMdiChild = true;
/// <summary>
/// Indicates whether control will delay call to OnResize base DataGridView method when control is running on MDI Child which was introduced as workaround to an issue in control.
/// </summary>
[DefaultValue(true), Browsable(false)]
public bool DelayResizeCallWhenMdiChild
{
get { return _DelayResizeCallWhenMdiChild; }
set { _DelayResizeCallWhenMdiChild = value; }
}
private eScrollBarAppearance _ScrollBarAppearance = eScrollBarAppearance.ApplicationScroll;
/// <summary>
/// Gets or sets the scroll-bar visual style.
/// </summary>
[DefaultValue(eScrollBarAppearance.ApplicationScroll), Category("Appearance"), Description("Gets or sets the scroll-bar visual style.")]
public eScrollBarAppearance ScrollBarAppearance
{
get { return _ScrollBarAppearance; }
set
{
_ScrollBarAppearance = value;
OnScrollBarAppearance();
}
}
private void OnScrollBarAppearance()
{
DGVScrollBar sbv = GetVScrollBar();
if (sbv != null)
sbv.AppStyleScrollBar = (_ScrollBarAppearance == eScrollBarAppearance.ApplicationScroll);
DGHScrollBar sbh = GetHScrollBar();
if (sbh != null)
sbh.AppStyleScrollBar = (_ScrollBarAppearance == eScrollBarAppearance.ApplicationScroll);
}
private void SetupScrollBars()
{
// Vertical Scroll Bar Replacement
Type t = typeof(System.Windows.Forms.DataGridView);
FieldInfo fi = t.GetField("vertScrollBar", BindingFlags.NonPublic | BindingFlags.Instance);
if(fi==null) return;
System.Windows.Forms.ScrollBar sb = fi.GetValue(this) as System.Windows.Forms.ScrollBar;
if (sb == null) return;
//sb.Scroll += new ScrollEventHandler(sb_Scroll); return;
MethodInfo mi = t.GetMethod("DataGridViewVScrolled", BindingFlags.NonPublic | BindingFlags.Instance);
if (mi == null) return;
DGVScrollBar newVSb = new DGVScrollBar();
newVSb.AppStyleScrollBar = (_ScrollBarAppearance == eScrollBarAppearance.ApplicationScroll);
newVSb.Minimum = sb.Minimum;
newVSb.Maximum = sb.Maximum;
newVSb.SmallChange = sb.SmallChange;
newVSb.LargeChange = sb.LargeChange;
newVSb.Top = sb.Top;
newVSb.AccessibleName = sb.AccessibleName;
newVSb.Left = sb.Left;
newVSb.Visible = sb.Visible;
newVSb.Scroll += (ScrollEventHandler)ScrollEventHandler.CreateDelegate(typeof(ScrollEventHandler), this, mi);
fi.SetValue(this, newVSb);
sb.Dispose();
this.Controls.Remove(sb);
this.Controls.Add(newVSb);
// Horizontal Scroll Bar Replacement
fi = t.GetField("horizScrollBar", BindingFlags.NonPublic | BindingFlags.Instance);
if (fi == null) return;
sb = fi.GetValue(this) as System.Windows.Forms.ScrollBar;
if (sb == null) return;
mi = t.GetMethod("DataGridViewHScrolled", BindingFlags.NonPublic | BindingFlags.Instance);
if (mi == null) return;
DGHScrollBar newHSb = new DGHScrollBar();
newHSb.AppStyleScrollBar = (_ScrollBarAppearance == eScrollBarAppearance.ApplicationScroll); ;
newHSb.Minimum = sb.Minimum;
newHSb.Maximum = sb.Maximum;
newHSb.SmallChange = sb.SmallChange;
newHSb.LargeChange = sb.LargeChange;
newHSb.Top = sb.Top;
newHSb.AccessibleName = sb.AccessibleName;
newHSb.Left = sb.Left;
newHSb.Visible = sb.Visible;
newHSb.RightToLeft = sb.RightToLeft;
newHSb.Scroll += (ScrollEventHandler)ScrollEventHandler.CreateDelegate(typeof(ScrollEventHandler), this, mi);
fi.SetValue(this, newHSb);
sb.Dispose();
this.Controls.Remove(sb);
this.Controls.Add(newHSb);
base.PerformLayout();
}
//void sb_Scroll(object sender, ScrollEventArgs e)
//{
// Console.WriteLine(e.NewValue);
//}
/// <summary>
/// Gets or sets whether selected column header is highlighted. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior"), Description("Indicates whether selected column header is highlighted.")]
public bool HighlightSelectedColumnHeaders
{
get { return m_HighlightSelectedColumnHeaders; }
set
{
m_HighlightSelectedColumnHeaders = value;
if(BarFunctions.IsHandleValid(this))
this.Invalidate();
}
}
/// <summary>
/// Gets or sets whether select all sign displayed in top-left corner of the grid is visible. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior"), Description("Indicates whether select all sign displayed in top-left corner of the grid is visible.")]
public bool SelectAllSignVisible
{
get { return m_SelectAllSignVisible; }
set
{
m_SelectAllSignVisible = value;
if (BarFunctions.IsHandleValid(this))
this.Invalidate();
}
}
/// <summary>
/// Gets or sets whether enhanced selection for the cells is painted in Office 2007 style. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether enhanced selection for the cells is painted in Office 2007 style")]
public bool PaintEnhancedSelection
{
get { return m_PaintEnhancedSelection; }
set
{
m_PaintEnhancedSelection = value;
if (BarFunctions.IsHandleValid(this))
this.Invalidate();
}
}
private bool _UseCustomBackgroundColor = false;
/// <summary>
/// Indicates whether BackgroundColor property set on DataGridView is obeyed instead of using system color scheme color.
/// </summary>
[DefaultValue(false), Category("Appearance"), Description("Indicates whether BackgroundColor property set on DataGridView is obeyed instead of using system color scheme color.")]
public bool UseCustomBackgroundColor
{
get { return _UseCustomBackgroundColor; }
set
{
_UseCustomBackgroundColor = value;
}
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,498 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewButtonXCell : DataGridViewButtonCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (null); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof (string)); }
}
#endregion
#endregion
#region GetContentBounds
/// <summary>
/// GetContentBounds
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <returns></returns>
protected override Rectangle GetContentBounds(Graphics graphics, DataGridViewCellStyle cellStyle, int rowIndex)
{
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(ColumnIndex, rowIndex, false);
cellBounds.Location = new Point(0, 0);
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
ButtonX bx = oc.ButtonX;
Rectangle rBt = GetButtonBounds(cellBounds, true);
if (bx.ButtonItem.SubItems.Count > 0)
rBt.Width -= bx.ButtonItem.SubItemsExpandWidth;
return (rBt);
}
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintButtonBackground(g, cellStyle, rBk);
PaintButtonContent(cellBounds, rowIndex, formattedValue, cellStyle, paintParts, bm);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintButtonBackground
/// <summary>
/// Paints the Button background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintButtonBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintButtonContent
/// <summary>
/// Paints the button background and content
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="bm"></param>
private void PaintButtonContent(Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Bitmap bm)
{
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
ButtonX bx = oc.ButtonX;
Rectangle rBt = GetButtonBounds(cellBounds, true);
if (rBt.Width > 0 && rBt.Height > 0)
{
bool mouseIsOver = bx.ButtonItem.MouseIsOver;
bool mouerIsOverExpand = bx.ButtonItem.MouseIsOverExpand;
bool mouseIsDown = bx.ButtonItem.MouseIsDown;
bool buttonIsExpanded = bx.ButtonItem.ButtonIsExpanded;
try
{
string s = oc.Text;
oc.InCellCallBack = true;
if (rowIndex != oc.ActiveRowIndex)
{
bx.ButtonItem.MouseIsOver = false;
bx.ButtonItem.MouseIsOverExpand = false;
bx.ButtonItem.MouseIsDown = false;
bx.ButtonItem.ButtonIsExpanded = false;
}
bx.Font = cellStyle.Font;
bx.ForeColor = cellStyle.ForeColor;
bx.BackColor = cellStyle.BackColor;
if (rowIndex < DataGridView.RowCount)
{
bx.Text = UseColumnTextForButtonValue ? s : GetValue(value);
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
}
else
{
bx.Text = "";
}
bx.Bounds = rBt;
bx.RecalcLayout();
bx.DrawToBitmap(bm, rBt);
}
finally
{
bx.ButtonItem.MouseIsOver = mouseIsOver;
bx.ButtonItem.MouseIsOverExpand = mouerIsOverExpand;
bx.ButtonItem.MouseIsDown = mouseIsDown;
bx.ButtonItem.ButtonIsExpanded = buttonIsExpanded;
oc.InCellCallBack = false;
}
}
}
#endregion
#endregion
#region Mouse processing
#region OnMouseEnter
/// <summary>
/// OnMouseEnter
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseEnter(int rowIndex)
{
base.OnMouseEnter(rowIndex);
DoMouseEnter(rowIndex);
}
/// <summary>
/// Establishes the given rowIndex as the
/// ActiveRowIndex.
/// </summary>
/// <param name="rowIndex"></param>
internal void DoMouseEnter(int rowIndex)
{
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
ButtonX bx = oc.ButtonX;
oc.CurrentRowIndex = rowIndex;
if (bx.Expanded == false)
{
oc.ActiveRowIndex = rowIndex;
bx.ButtonItem.InternalMouseEnter();
RefreshButton(ColumnIndex, rowIndex);
}
}
#endregion
#region OnMouseLeave
/// <summary>
/// Processes MouseLeave events
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseLeave(int rowIndex)
{
base.OnMouseLeave(rowIndex);
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
ButtonX bx = oc.ButtonX;
oc.CurrentRowIndex = -1;
if (bx.Expanded == false)
{
oc.ActiveRowIndex = -1;
bx.ButtonItem.InternalMouseLeave();
RefreshButton(ColumnIndex, rowIndex);
}
}
#endregion
#region OnMouseMove
/// <summary>
/// Processes MouseMove events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
{
base.OnMouseMove(e);
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn) OwningColumn;
ButtonX bx = oc.ButtonX;
if (oc.ActiveRowIndex == e.RowIndex || bx.Expanded == false)
{
bx.ButtonItem.InternalMouseMove(
new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta));
RefreshButton(e.ColumnIndex, e.RowIndex);
}
}
#endregion
#region OnMouseDown
/// <summary>
/// Processes MouseDown events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
{
base.OnMouseDown(e);
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn) OwningColumn;
ButtonX bx = oc.ButtonX;
if (DataGridView.Controls.Contains(bx) == false)
DataGridView.Controls.Add(bx);
if (oc.ExpandClosed == false || bx.ButtonItem.MouseIsOverExpand == false)
{
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
Rectangle rBt = GetButtonBounds(cellBounds, false);
Point pt = e.Location;
pt.Offset(rBt.Location);
if (rBt.Contains(pt) == true)
{
bx.Bounds = rBt;
bx.ButtonItem.InternalMouseDown(
new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta));
DataGridView.Invalidate(rBt);
}
}
oc.ExpandClosed = false;
}
#endregion
#region OnMouseUp
/// <summary>
/// Processes MouseUp events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
{
base.OnMouseUp(e);
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn) OwningColumn;
ButtonX bx = oc.ButtonX;
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
Rectangle rBt = GetButtonBounds(cellBounds, false);
DataGridView.Invalidate(rBt);
bx.Bounds = rBt;
bx.ButtonItem.InternalMouseUp(
new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta));
}
#endregion
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetButtonBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="localize"></param>
/// <returns></returns>
private Rectangle GetButtonBounds(Rectangle cellBounds, bool localize)
{
DataGridViewButtonXColumn oc = (DataGridViewButtonXColumn)OwningColumn;
cellBounds.Width -= (oc.DividerWidth + 3);
cellBounds.Height -= 3;
if (localize == true)
cellBounds.Location = new Point(0, 0);
cellBounds.X++;
cellBounds.Y++;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private string GetValue(object value)
{
return (value != Convert.DBNull ? Convert.ToString(value) : "" );
}
#endregion
#region RefreshButton
/// <summary>
/// Initiates the refresh of the cell button
/// </summary>
/// <param name="columnIndex"></param>
/// <param name="rowIndex"></param>
private void RefreshButton(int columnIndex, int rowIndex)
{
if (DataGridView != null)
{
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(columnIndex, rowIndex, false);
Rectangle rBt = GetButtonBounds(cellBounds, false);
DataGridView.Invalidate(rBt);
}
}
#endregion
}
}

View File

@@ -0,0 +1,751 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "ButtonX.ButtonX.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewButtonXColumn : DataGridViewButtonColumn, IDataGridViewColumn
{
#region Events
[Description("Occurs right before a Button Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
[Description("Occurs when a Button Cell is Clicked.")]
public event EventHandler<EventArgs> Click;
#endregion
#region Private variables
private ButtonX _ButtonX;
private int _ActiveRowIndex = -1;
private int _CurrentRowIndex = -1;
private bool _ExpandClosed;
private bool _InCellCallBack;
private Bitmap _CellBitmap;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewButtonXColumn()
{
CellTemplate = new DataGridViewButtonXCell();
_ButtonX = new ButtonX();
_ButtonX.Visible = false;
_ButtonX.FadeEffect = false;
HookEvents(true);
}
#region Internal properties
#region ActiveRowIndex
/// <summary>
/// Gets or sets the active row index
/// </summary>
internal int ActiveRowIndex
{
get { return (_ActiveRowIndex); }
set { _ActiveRowIndex = value; }
}
#endregion
#region ButtonX
/// <summary>
/// Gets the Control Button
/// </summary>
internal ButtonX ButtonX
{
get { return (_ButtonX); }
}
#endregion
#region CurrentRowIndex
/// <summary>
/// Gets or sets the Current row index
/// </summary>
internal int CurrentRowIndex
{
get { return (_CurrentRowIndex); }
set { _CurrentRowIndex = value; }
}
#endregion
#region ExpandClosed
/// <summary>
/// Gets or sets a expanded button
/// was just closed
/// </summary>
internal bool ExpandClosed
{
get { return (_ExpandClosed); }
set { _ExpandClosed = value; }
}
#endregion
#region InCellCallBack
/// <summary>
/// Gets or sets the cell callback state
/// </summary>
internal bool InCellCallBack
{
get { return (_InCellCallBack); }
set { _InCellCallBack = value; }
}
#endregion
#endregion
#region Public properties
#region AutoCheckOnClick
/// <summary>
/// Gets or sets whether Checked property is automatically inverted, button checked/unchecked, when button is clicked. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Behavior")]
[Description("Indicates whether Checked property is automatically inverted when button is clicked.")]
public bool AutoCheckOnClick
{
get { return (_ButtonX.AutoCheckOnClick); }
set { _ButtonX.AutoCheckOnClick = value; }
}
#endregion
#region AutoExpandOnClick
/// <summary>
/// Indicates whether the button will auto-expand when clicked.
/// When button contains sub-items, sub-items will be shown only if user
/// click the expand part of the button. Setting this property to true will expand the button and show sub-items when user
/// clicks anywhere inside of the button. Default value is false which indicates that button is expanded only
/// if its expand part is clicked.
/// </summary>
[DefaultValue(false), Browsable(true), DevCoBrowsable(true), Category("Behavior")]
[Description("Indicates whether the button will auto-expand (display pop-up menu or toolbar) when clicked.")]
public virtual bool AutoExpandOnClick
{
get { return (_ButtonX.AutoExpandOnClick); }
set { _ButtonX.AutoExpandOnClick = value; }
}
#endregion
#region Checked
/// <summary>
/// Gets or set a value indicating whether the button is in the checked state.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), DefaultValue(false)]
[Description("Indicates whether item is checked or not.")]
public virtual bool Checked
{
get { return (_ButtonX.Checked); }
set { _ButtonX.Checked = value; }
}
#endregion
#region ColorScheme
/// <summary>
/// Gets or sets button Color Scheme. ColorScheme does not apply to Office2007 styled buttons.
/// </summary>
[Browsable(false), DevCoBrowsable(false), Category("Appearance")]
[Description("Gets or sets Bar Color Scheme."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ColorScheme ColorScheme
{
get { return (_ButtonX.ColorScheme); }
set { _ButtonX.ColorScheme = value; }
}
#endregion
#region ColorTable
/// <summary>
/// Gets or sets the predefined color of the button. Color specified applies to buttons with Office 2007 style only. It does not have
/// any effect on other styles. Default value is eButtonColor.BlueWithBackground
/// </summary>
[Browsable(true), DevCoBrowsable(false), DefaultValue(eButtonColor.BlueWithBackground), Category("Appearance")]
[Description("Indicates predefined color of button when Office 2007 style is used.")]
[NotifyParentProperty(true)]
public eButtonColor ColorTable
{
get { return (_ButtonX.ColorTable); }
set { _ButtonX.ColorTable = value; }
}
#endregion
#region CustomColorName
/// <summary>
/// Gets or sets the custom color name. Name specified here must be represented by the corresponding object with the same name that is part
/// of the Office2007ColorTable.ButtonItemColors collection. See documentation for Office2007ColorTable.ButtonItemColors for more information.
/// If color table with specified name cannot be found default color will be used. Valid settings for this property override any
/// setting to the Color property. Applies to items with Office 2007 style only.
/// </summary>
[Browsable(true), DevCoBrowsable(false), DefaultValue(""), Category("Appearance")]
[Description("Indicates custom color table name for the button when Office 2007 style is used.")]
public string CustomColorName
{
get { return (_ButtonX.CustomColorName); }
set { _ButtonX.CustomColorName = value; }
}
#endregion
#region DisabledImage
/// <summary>
/// Specifies the image for the button when items Enabled property is set to false.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(null), Category("Appearance")]
[Description("The image that will be displayed when item is disabled.")]
public Image DisabledImage
{
get { return (_ButtonX.DisabledImage); }
set { _ButtonX.DisabledImage = value; }
}
#endregion
#region EnableMarkup
/// <summary>
/// Gets or sets whether text-markup support is enabled for items Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the item instead of it being parsed as text-markup.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether text-markup support is enabled for items Text property.")]
public bool EnableMarkup
{
get { return (_ButtonX.EnableMarkup); }
set { _ButtonX.EnableMarkup = value; }
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_ButtonX.Enabled); }
set { _ButtonX.Enabled = value; }
}
#endregion
#region HotTrackingStyle
/// <summary>
/// Indicates the way button is rendering the mouse over state. Setting the value to
/// Color will render the image in gray-scale when mouse is not over the item.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(eHotTrackingStyle.Default), Category("Appearance")]
[Description("Indicates the button mouse over tracking style. Setting the value to Color will render the image in gray-scale when mouse is not over the item.")]
public eHotTrackingStyle HotTrackingStyle
{
get { return (_ButtonX.HotTrackingStyle); }
set { _ButtonX.HotTrackingStyle = value; }
}
#endregion
#region HoverImage
/// <summary>
/// Specifies the image for the button when mouse is over the item.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(null), Category("Appearance")]
[Description("The image that will be displayed when mouse hovers over the item.")]
public Image HoverImage
{
get { return (_ButtonX.HoverImage); }
set { _ButtonX.HoverImage = value; }
}
#endregion
#region Image
/// <summary>
/// Specifies the Button image.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(null), Category("Appearance")]
[Description("The image that will be displayed on the face of the button.")]
public Image Image
{
get { return (_ButtonX.Image); }
set { _ButtonX.Image = value; }
}
#endregion
#region ImageFixedSize
/// <summary>
/// Sets fixed size of the image. Image will be scaled and painted it size specified.
/// </summary>
[Browsable(true)]
public Size ImageFixedSize
{
get { return (_ButtonX.ImageFixedSize); }
set { _ButtonX.ImageFixedSize = value; }
}
/// <summary>
/// Gets whether ImageFixedSize property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeImageFixedSize()
{
return (_ButtonX.ShouldSerializeImageFixedSize());
}
#endregion
#region ImagePosition
/// <summary>
/// Gets/Sets the image position inside the button.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(eImagePosition.Left), Category("Appearance")]
[Description("The alignment of the image in relation to text displayed by this item.")]
public eImagePosition ImagePosition
{
get { return (_ButtonX.ImagePosition); }
set { _ButtonX.ImagePosition = value; }
}
#endregion
#region ImageTextSpacing
/// <summary>
/// Gets or sets the amount of spacing between button image if specified and text.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout")]
[Description("Indicates amount of spacing between button image if specified and text.")]
public int ImageTextSpacing
{
get { return (_ButtonX.ImageTextSpacing); }
set { _ButtonX.ImageTextSpacing = value; }
}
#endregion
#region PopupSide
/// <summary>
/// Gets or sets the location of popup in relation to it's parent.
/// </summary>
[Browsable(true), DevCoBrowsable(false), DefaultValue(ePopupSide.Default)]
[Description("Indicates location of popup in relation to it's parent.")]
public ePopupSide PopupSide
{
get { return (_ButtonX.PopupSide); }
set { _ButtonX.PopupSide = value; }
}
#endregion
#region PressedImage
/// <summary>
/// Specifies the image for the button when mouse left button is pressed.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(null), Category("Appearance")]
[Description("The image that will be displayed when item is pressed.")]
public Image PressedImage
{
get { return (_ButtonX.PressedImage); }
set { _ButtonX.PressedImage = value; }
}
#endregion
#region Shape
/// <summary>
/// Gets or sets an shape descriptor for the button
/// which describes the shape of the button. Default value is null
/// which indicates that system default shape is used.
/// </summary>
[DefaultValue(null)]
[Editor("DevComponents.DotNetBar.Design.ShapeTypeEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(UITypeEditor))]
[TypeConverter("DevComponents.DotNetBar.Design.ShapeStringConverter, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public ShapeDescriptor Shape
{
get { return (_ButtonX.Shape); }
set { _ButtonX.Shape = value; }
}
#endregion
#region ShowSubItems
/// <summary>
/// Gets or sets whether button displays the expand part that indicates that button has popup.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(true), Category("Behavior")]
[Description("Determines whether sub-items are displayed.")]
public bool ShowSubItems
{
get { return (_ButtonX.ShowSubItems); }
set { _ButtonX.ShowSubItems = value; }
}
#endregion
#region SplitButton
/// <summary>
/// Gets or sets whether button appears as split button. Split button appearance
/// divides button into two parts. Image which raises the click event when clicked
/// and text and expand sign which shows button sub items on popup menu when clicked.
/// Button must have both text and image visible (ButtonStyle property) in order to
/// appear as a full split button.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Appearance")]
[Description("Indicates whether button appears as split button.")]
public bool SplitButton
{
get { return (_ButtonX.SplitButton); }
set { _ButtonX.SplitButton = value; }
}
#endregion
#region Style
/// <summary>
/// Gets/Sets the visual style for the button.
/// </summary>
[Category("Appearance"), Description("Specifies the visual style of the button.")]
[DefaultValue(eDotNetBarStyle.Office2007)]
public eDotNetBarStyle Style
{
get { return (_ButtonX.Style); }
set { _ButtonX.Style = value; }
}
#endregion
#region SubItems
/// <summary>
/// Returns the collection of sub items.
/// </summary>
[Browsable(false), DevCoBrowsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SubItemsCollection SubItems
{
get { return (_ButtonX.SubItems); }
}
#endregion
#region SubItemsExpandWidth
/// <summary>
/// Gets or sets the width of the expand part of the button item.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(12), Category("Behavior")]
[Description("Indicates the width of the expand part of the button item.")]
public int SubItemsExpandWidth
{
get { return (_ButtonX.SubItemsExpandWidth); }
set { _ButtonX.SubItemsExpandWidth = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the default Text to display on the Button
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue("")]
[Description("Indicates the default Text to display on the Button.")]
public new string Text
{
get
{
return (_InCellCallBack == true ?
_ButtonX.Text : base.Text);
}
set
{
if (_InCellCallBack == true)
_ButtonX.Text = value;
else
base.Text = value;
}
}
#endregion
#region TextAlignment
/// <summary>
/// Gets or sets the text alignment. Applies only when button text is not composed using text markup. Default value is center.
/// </summary>
[Browsable(true), DefaultValue(eButtonTextAlignment.Center), Category("Appearance")]
[Description("Indicates text alignment. Applies only when button text is not composed using text markup. Default value is center.")]
public eButtonTextAlignment TextAlignment
{
get { return (_ButtonX.TextAlignment); }
set { _ButtonX.TextAlignment = value; }
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// Hooks or unhooks our system events
/// </summary>
/// <param name="hook"></param>
private void HookEvents(bool hook)
{
if (hook == true)
{
_ButtonX.ButtonItem.Click += ButtonItem_Click;
_ButtonX.ButtonItem.ExpandChange += ButtonItem_ExpandChange;
}
else
{
_ButtonX.ButtonItem.Click -= ButtonItem_Click;
_ButtonX.ButtonItem.ExpandChange -= ButtonItem_ExpandChange;
}
}
#endregion
#region Event processing
#region ButtonItem_ExpandChange
/// <summary>
/// Processes Button expand changes
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonItem_ExpandChange(object sender, EventArgs e)
{
if (_ButtonX.ButtonItem.Expanded == false)
{
DataGridView.InvalidateCell(Index, ActiveRowIndex);
_ExpandClosed = (_ActiveRowIndex == _CurrentRowIndex);
_ActiveRowIndex = -1;
if (_CurrentRowIndex >= 0)
{
DataGridViewButtonXCell cell =
DataGridView.Rows[_CurrentRowIndex].Cells[Index] as DataGridViewButtonXCell;
if (cell != null)
cell.DoMouseEnter(_CurrentRowIndex);
}
}
}
#endregion
#region ButtonItem_Click
/// <summary>
/// ButtonItem_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonItem_Click(object sender, EventArgs e)
{
if (Click != null)
Click(sender, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewButtonXColumn bc = base.Clone() as DataGridViewButtonXColumn;
if (bc != null)
{
_ButtonX.ButtonItem.InternalCopyToItem(bc.ButtonX.ButtonItem);
bc.Enabled = Enabled;
bc.TextAlignment = TextAlignment;
bc.ImageTextSpacing = ImageTextSpacing;
bc.Shape = Shape;
}
return (bc);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the ButtonX control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
HookEvents(false);
if (disposing == true)
_ButtonX.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
}
#region BeforeCellPaintEventArgs
/// <summary>
/// BeforeCellPaintEventArgs
/// </summary>
public class BeforeCellPaintEventArgs : EventArgs
{
#region Private variables
private int _RowIndex;
private int _ColumnIndex;
#endregion
public BeforeCellPaintEventArgs(int rowIndex, int columnIndex)
{
_RowIndex = rowIndex;
_ColumnIndex = columnIndex;
}
#region Public properties
/// <summary>
/// RowIndex of cell being painted
/// </summary>
public int RowIndex
{
get { return (_RowIndex); }
}
/// <summary>
/// ColumnIndex of cell being painted
/// </summary>
public int ColumnIndex
{
get { return (_ColumnIndex); }
}
#endregion
}
#endregion
}

View File

@@ -0,0 +1,696 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewCheckBoxXCell : DataGridViewCell
{
#region Private variables
private bool _MouseEntered;
private string _Text;
#endregion
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (null); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof(string)); }
}
#endregion
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetContentBounds(editingControlBounds);
if (cellStyle != null)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.TopCenter:
editingControlBounds.X += (editingControlBounds.Width - r.Width) / 2;
break;
case DataGridViewContentAlignment.TopRight:
editingControlBounds.X = (editingControlBounds.Right - r.Width);
break;
case DataGridViewContentAlignment.MiddleLeft:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.MiddleCenter:
editingControlBounds.X += (editingControlBounds.Width - r.Width) / 2;
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.X = (editingControlBounds.Right - r.Width);
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
case DataGridViewContentAlignment.BottomCenter:
editingControlBounds.X += (editingControlBounds.Width - r.Width) / 2;
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.X = (editingControlBounds.Right - r.Width);
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
if (editingControlBounds.Y < 1)
editingControlBounds.Y = 1;
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = Size.Empty;
if (constraintSize.Width == 0)
{
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null)
{
GetFormattedValue(GetValue(rowIndex), rowIndex,
ref cellStyle, null, null, new DataGridViewDataErrorContexts());
if (rowIndex < DataGridView.RowCount)
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
CheckBoxX cb = oc.CheckBoxX;
SizeF sf = graphics.MeasureString(cb.Text, cellStyle.Font);
preferredSize.Width = (int) sf.Width + 4;
preferredSize.Height = cb.Height;
preferredSize.Width += cb.CheckBoxItem.CheckSignSize.Width;
}
}
return (preferredSize);
}
#endregion
#region GetFormattedValue
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
return (base.GetFormattedValue(value, rowIndex,
ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewCheckBoxXColumn oc = (DataGridViewCheckBoxXColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintButtonBackground(g, cellStyle, rBk);
PaintButtonContent(cellBounds, rowIndex, value, cellStyle, paintParts, g);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintButtonBackground
/// <summary>
/// Paints the Button background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintButtonBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintButtonContent
/// <summary>
/// Paints the button background and content
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="g"></param>
private void PaintButtonContent(Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Graphics g)
{
DataGridViewCheckBoxXColumn oc = (DataGridViewCheckBoxXColumn) OwningColumn;
CheckBoxX bx = oc.CheckBoxX;
string text = bx.Text;
bool isChecked = bx.Checked;
object checkValue = bx.CheckValue;
CheckState checkState = bx.CheckState;
bool isMouseOver = bx.CheckBoxItem.IsMouseOver;
bool isMouseDown = bx.CheckBoxItem.IsMouseDown;
GraphicsState gs = g.Save();
try
{
oc.InCellCallBack = true;
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
bx.CheckValue = (oc.ThreeState == true) ? value : GetCheckValue(oc, value);
bx.Font = cellStyle.Font;
bx.ForeColor = cellStyle.ForeColor;
bx.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
if (rowIndex != oc.ActiveRowIndex)
{
bx.CheckBoxItem.IsMouseOver = false;
bx.CheckBoxItem.IsMouseDown = false;
}
if (rowIndex < DataGridView.RowCount)
{
bx.Text = text;
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
}
else
{
bx.Text = "";
}
_Text = bx.Text;
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
bx.CallBasePaintBackground = false;
g.TranslateTransform(r.X, r.Y);
bx.Bounds = r;
bx.RecalcLayout();
bx.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
bx.Text = text;
if (bx.ThreeState == true)
bx.CheckValue = checkValue;
bx.Checked = isChecked;
bx.CheckState = checkState;
bx.CheckBoxItem.IsMouseOver = isMouseOver;
bx.CheckBoxItem.IsMouseDown = isMouseDown;
g.Restore(gs);
oc.InCellCallBack = false;
}
}
#region GetCheckValue
private bool GetCheckValue(DataGridViewCheckBoxXColumn oc, object value)
{
if (value == null || value == DBNull.Value)
return (false);
Type type = value.GetType();
if (type == typeof(bool))
return ((bool)value);
if (type == typeof(string))
{
string s = (string)value;
if (oc.CheckValueChecked is string && s.Equals(oc.CheckValueChecked))
return (true);
if (oc.CheckValueUnchecked is string && s.Equals(oc.CheckValueUnchecked))
return (false);
}
else
{
int n = Convert.ToInt32(value);
if (n == 1)
return (true);
}
return (false);
}
#endregion
#endregion
#endregion
#region Mouse processing
#region OnMouseEnter
/// <summary>
/// OnMouseEnter
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseEnter(int rowIndex)
{
base.OnMouseEnter(rowIndex);
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null && DataGridView != null)
{
_MouseEntered = false;
oc.ActiveRowIndex = rowIndex;
ToolTipText = _Text;
RefreshCell(ColumnIndex, rowIndex);
}
}
#endregion
#region OnMouseLeave
/// <summary>
/// Processes MouseLeave events
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseLeave(int rowIndex)
{
base.OnMouseLeave(rowIndex);
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null && DataGridView != null)
{
oc.ActiveRowIndex = -1;
if (_MouseEntered == true)
{
_MouseEntered = false;
oc.CheckBoxX.CheckBoxItem.InternalMouseLeave();
}
RefreshCell(ColumnIndex, rowIndex);
}
}
#endregion
#region OnMouseMove
/// <summary>
/// Processes MouseMove events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
{
base.OnMouseMove(e);
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null && DataGridView != null)
{
if (this.ReadOnly == true || oc.ReadOnly == true || DataGridView.ReadOnly == true)
return;
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
cellBounds.X = 0;
cellBounds.Y = 0;
DataGridViewCellStyle cellStyle = DataGridView.Columns[e.ColumnIndex].InheritedStyle;
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
Point pt = new Point(e.X - r.X, e.Y - r.Y);
if (oc.CheckBoxX.CheckBoxItem.DisplayRectangle.Contains(pt) == true)
{
if (_MouseEntered == false)
{
_MouseEntered = true;
oc.CheckBoxX.CheckBoxItem.InternalMouseEnter();
}
}
else
{
if (_MouseEntered == true)
{
_MouseEntered = false;
oc.CheckBoxX.CheckBoxItem.InternalMouseLeave();
}
}
oc.CheckBoxX.CheckBoxItem.InternalMouseMove(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
RefreshCell(e.ColumnIndex, e.RowIndex);
}
}
#endregion
#region OnMouseDown
/// <summary>
/// Processes MouseDown events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
{
base.OnMouseDown(e);
if (_MouseEntered == true)
{
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null && !oc.ReadOnly && DataGridView != null)
{
oc.DownRowIndex = e.RowIndex;
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
cellBounds.X = 0;
cellBounds.Y = 0;
DataGridViewCellStyle cellStyle = DataGridView.Columns[e.ColumnIndex].InheritedStyle;
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
Point pt = new Point(e.X - r.X, e.Y - r.Y);
if (oc.CheckBoxX.CheckBoxItem.DisplayRectangle.Contains(pt) == true)
{
oc.CheckBoxX.CheckValue = GetValue(e.RowIndex);
oc.CheckBoxX.CheckBoxItem.InternalMouseDown(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
RefreshCell(e.ColumnIndex, e.RowIndex);
}
}
}
}
#endregion
#region OnMouseUp
/// <summary>
/// Processes MouseUp events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
{
base.OnMouseUp(e);
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null && !oc.ReadOnly && DataGridView != null)
{
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
cellBounds.X = 0;
cellBounds.Y = 0;
DataGridViewCellStyle cellStyle = DataGridView.Columns[e.ColumnIndex].InheritedStyle;
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
Point pt = new Point(e.X - r.X, e.Y - r.Y);
oc.CheckBoxX.CheckBoxItem.InternalMouseUp(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
if (e.RowIndex == oc.DownRowIndex)
{
if (r.Contains(e.Location) == true)
Value = oc.CheckBoxX.CheckValue;
RefreshCell(e.ColumnIndex, e.RowIndex);
}
oc.DownRowIndex = -1;
}
}
#endregion
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewCheckBoxXColumn oc = (DataGridViewCheckBoxXColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetContentBounds
/// <summary>
/// Gets the Content bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetContentBounds(Rectangle cellBounds)
{
DataGridViewCheckBoxXColumn oc = OwningColumn as DataGridViewCheckBoxXColumn;
if (oc != null)
{
if (oc.CheckBoxX.Parent == null)
{
Form form = oc.DataGridView.FindForm();
if (form != null)
oc.CheckBoxX.Parent = form;
}
oc.CheckBoxX.CheckBoxItem.RecalcSize();
cellBounds.Width = Math.Min(oc.CheckBoxX.CheckBoxItem.WidthInternal, cellBounds.Width);
cellBounds.Width -= (oc.DividerWidth + 3);
cellBounds.Height = oc.CheckBoxX.CheckBoxItem.HeightInternal;
}
return (cellBounds);
}
#endregion
#region RefreshCell
/// <summary>
/// Initiates the refresh of the cell
/// </summary>
/// <param name="columnIndex"></param>
/// <param name="rowIndex"></param>
private void RefreshCell(int columnIndex, int rowIndex)
{
if (DataGridView != null)
DataGridView.InvalidateCell(columnIndex, rowIndex);
}
#endregion
}
}

View File

@@ -0,0 +1,562 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "Controls.CheckBoxX.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewCheckBoxXColumn : DataGridViewColumn, IDataGridViewColumn
{
#region Events
[Description("Occurs right before a CheckBoxX Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
[Description("Occurs when a CheckBoxX Cell is Clicked.")]
public event EventHandler<EventArgs> Click;
[Description("Occurs when a CheckBoxX Cell is DoubleClicked.")]
public event EventHandler<EventArgs> DoubleClicked;
#endregion
#region Private variables
private CheckBoxX _CheckBoxX;
private int _ActiveRowIndex = -1;
private int _CurrentRowIndex = -1;
private int _DownRowIndex = -1;
private bool _InCellCallBack;
private Bitmap _CellBitmap;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewCheckBoxXColumn()
{
CellTemplate = new DataGridViewCheckBoxXCell();
_CheckBoxX = new CheckBoxX();
_CheckBoxX.Visible = false;
_CheckBoxX.CheckValueChecked = true;
_CheckBoxX.CheckValueUnchecked = false;
HookEvents(true);
}
#region Internal properties
#region ActiveRowIndex
/// <summary>
/// Gets or sets the active row index
/// </summary>
internal int ActiveRowIndex
{
get { return (_ActiveRowIndex); }
set { _ActiveRowIndex = value; }
}
#endregion
#region CheckBoxX
/// <summary>
/// Gets the Control Button
/// </summary>
internal CheckBoxX CheckBoxX
{
get { return (_CheckBoxX); }
}
#endregion
#region CurrentRowIndex
/// <summary>
/// Gets or sets the Current row index
/// </summary>
internal int CurrentRowIndex
{
get { return (_CurrentRowIndex); }
set { _CurrentRowIndex = value; }
}
#endregion
#region DownRowIndex
/// <summary>
/// Gets or sets the MouseDown row index
/// </summary>
internal int DownRowIndex
{
get { return (_DownRowIndex); }
set { _DownRowIndex = value; }
}
#endregion
#region InCellCallBack
/// <summary>
/// Gets or sets the cell callback state
/// </summary>
internal bool InCellCallBack
{
get { return (_InCellCallBack); }
set { _InCellCallBack = value; }
}
#endregion
#endregion
#region Public properties
#region CheckBoxImageChecked
/// <summary>
/// Gets or sets the custom image that is displayed instead default check box representation when check box is checked.
/// </summary>
[DefaultValue(null), Category("CheckBox Images"), Description("Indicates custom image that is displayed instead default check box representation when check box is checked")]
public Image CheckBoxImageChecked
{
get { return _CheckBoxX.CheckBoxImageChecked; }
set
{
_CheckBoxX.CheckBoxImageChecked = value;
}
}
#endregion
#region CheckBoxImageUnChecked
/// <summary>
/// Gets or sets the custom image that is displayed instead default check box representation when check box is unchecked.
/// </summary>
[DefaultValue(null), Category("CheckBox Images"), Description("Indicates custom image that is displayed instead default check box representation when check box is unchecked")]
public Image CheckBoxImageUnChecked
{
get { return _CheckBoxX.CheckBoxImageUnChecked; }
set
{
_CheckBoxX.CheckBoxImageUnChecked = value;
}
}
#endregion
#region CheckBoxImageIndeterminate
/// <summary>
/// Gets or sets the custom image that is displayed instead default check box representation when check box is in indeterminate state.
/// </summary>
[DefaultValue(null), Category("CheckBox Images"), Description("Indicates custom image that is displayed instead default check box representation when check box is in indeterminate state")]
public Image CheckBoxImageIndeterminate
{
get { return _CheckBoxX.CheckBoxImageIndeterminate; }
set
{
_CheckBoxX.CheckBoxImageIndeterminate = value;
}
}
#endregion
#region CheckBoxPosition
/// <summary>
/// Gets or sets the check box position relative to the text.
/// Default value is Left.
/// </summary>
[Browsable(true), DefaultValue(eCheckBoxPosition.Left), Category("Appearance")]
[Description("Indicates the check box position relative to the text.")]
public eCheckBoxPosition CheckBoxPosition
{
get { return (_CheckBoxX.CheckBoxPosition); }
set { _CheckBoxX.CheckBoxPosition = value; }
}
#endregion
#region Checked
/// <summary>
/// Gets or set a value indicating whether the button is in the checked state.
/// </summary>
[Browsable(false)]
public virtual bool Checked
{
get { return (_CheckBoxX.Checked); }
set { _CheckBoxX.Checked = value; }
}
#endregion
#region CheckState
/// <summary>
/// Specifies the state of the control, that can be
/// checked, unchecked, or set to an indeterminate state.
/// </summary>
[Browsable(false)]
public CheckState CheckState
{
get { return (_CheckBoxX.CheckState); }
set { _CheckBoxX.CheckState = value; }
}
#endregion
#region CheckValue
/// <summary>
/// CheckValue
/// </summary>
[Browsable(false)]
public object CheckValue
{
get { return (_CheckBoxX.CheckValue); }
set { _CheckBoxX.CheckValue = value; }
}
#endregion
#region CheckValueChecked
/// <summary>
/// Gets or sets the value that represents the Checked state value of the check
/// box when CheckValue property is set to that value. Default value is null.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior"), TypeConverter(typeof(StringConverter))]
[Description("Represents the Checked state value of the check box when CheckValue property is set to that value. Note that in the designer, this value type is always a string.")]
public object CheckValueChecked
{
get { return (_CheckBoxX.CheckValueChecked); }
set { _CheckBoxX.CheckValueChecked = value; }
}
#endregion
#region CheckValueIndeterminate
/// <summary>
/// Gets or sets the value that represents the Indeterminate state of the check
/// box when CheckValue property is set to that value. Default value is null.
/// </summary>
[Browsable(true), DefaultValue(null), Category("Behavior"), TypeConverter(typeof(StringConverter))]
[Description("Represents the Indeterminate state value of the check box when CheckValue property is set to that value. Note that in the designer, this value type is always a string.")]
public object CheckValueIndeterminate
{
get { return (_CheckBoxX.CheckValueIndeterminate); }
set { _CheckBoxX.CheckValueIndeterminate = value; }
}
#endregion
#region CheckValueUnchecked
/// <summary>
/// Gets or sets the value that represents the Unchecked state value of check
/// box when CheckValue property is set to that value. Default value is 'N'.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Behavior"), TypeConverter(typeof(StringConverter))]
[Description("Represents the Unchecked state value of the check box when CheckValue property is set to that value. Note that in the designer, this value type is always a string.")]
public object CheckValueUnchecked
{
get { return (_CheckBoxX.CheckValueUnchecked); }
set { _CheckBoxX.CheckValueUnchecked = value; }
}
#endregion
#region ConsiderEmptyStringAsNull
/// <summary>
/// Gets or sets whether empty string is consider as null value
/// during CheckValue value comparison. Default value is true.
/// </summary>
[DefaultValue(true), Category("Behavior"), Browsable(true)]
[Description("Indicates whether empty string is consider as null value during CheckValue value comparison.")]
public bool ConsiderEmptyStringAsNull
{
get { return (_CheckBoxX.ConsiderEmptyStringAsNull); }
set { _CheckBoxX.ConsiderEmptyStringAsNull = value; }
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_CheckBoxX.Enabled); }
set { _CheckBoxX.Enabled = value; }
}
#endregion
#region EnableMarkup
/// <summary>
/// Gets or sets whether text-markup support is enabled for controls
/// Text property. Default value is true. Set this property to false to
/// display HTML or other markup in the control instead of it being parsed as text-markup.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether text-markup support is enabled for controls Text property.")]
public bool EnableMarkup
{
get { return (_CheckBoxX.EnableMarkup); }
set { _CheckBoxX.EnableMarkup = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the default Text to display
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue("")]
[Description("Indicates the default Text to display.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string Text
{
get { return (_CheckBoxX.Text); }
set { _CheckBoxX.Text = value; }
}
#endregion
#region TextColor
/// <summary>
/// Gets or sets the text color. Default value is
/// Color.Empty which indicates that default color is used.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates control text color.")]
public Color TextColor
{
get { return (_CheckBoxX.TextColor); }
set { _CheckBoxX.TextColor = value; }
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTextColor()
{
return (_CheckBoxX.TextColor.IsEmpty == false);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTextColor()
{
TextColor = Color.Empty;
}
#endregion
#region TextVisible
/// <summary>
/// Gets or sets whether text assigned to the check box is visible.
/// Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether text assigned to the check box is visible.")]
public bool TextVisible
{
get { return (_CheckBoxX.TextVisible); }
set { _CheckBoxX.TextVisible = value; }
}
#endregion
#region ThreeState
/// <summary>
/// Gets or sets a value indicating whether the CheckBox will allow
/// three check states rather than two. If the ThreeState property is
/// set to true CheckState property should be used instead of Checked
/// property to set the extended state of the control.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(false)]
[Description("Indicates whether the CheckBox will allow three check states rather than two.")]
public bool ThreeState
{
get { return (_CheckBoxX.ThreeState); }
set { _CheckBoxX.ThreeState = value; }
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// HookEvents
/// </summary>
/// <param name="hook"></param>
private void HookEvents(bool hook)
{
if (hook == true)
{
_CheckBoxX.CheckBoxItem.Click += CheckBoxItem_Click;
_CheckBoxX.CheckBoxItem.DoubleClick += CheckBoxItem_DoubleClick;
}
else
{
_CheckBoxX.CheckBoxItem.Click -= CheckBoxItem_Click;
_CheckBoxX.CheckBoxItem.DoubleClick -= CheckBoxItem_DoubleClick;
}
}
#endregion
#region Event processing
#region CheckBoxItem_Click
/// <summary>
/// CheckBoxItem_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void CheckBoxItem_Click(object sender, EventArgs e)
{
if (Click != null)
Click(sender, e);
}
#endregion
#region CheckBoxItem_DoubleClick
/// <summary>
/// CheckBoxItem_DoubleClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void CheckBoxItem_DoubleClick(object sender, EventArgs e)
{
if (DoubleClicked != null)
DoubleClicked(sender, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewCheckBoxXColumn cb = base.Clone() as DataGridViewCheckBoxXColumn;
if (cb != null)
{
_CheckBoxX.CheckBoxItem.InternalCopyToItem(cb.CheckBoxX.CheckBoxItem);
cb.CheckValue = CheckValue;
cb.CheckValueChecked = CheckValueChecked;
cb.CheckValueIndeterminate = CheckValueIndeterminate;
cb.CheckValueUnchecked = CheckValueUnchecked;
cb.ConsiderEmptyStringAsNull = ConsiderEmptyStringAsNull;
cb.Enabled = Enabled;
cb.Text = Text;
}
return (cb);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the ButtonX control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
HookEvents(false);
if (disposing == true)
_CheckBoxX.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
}
}

View File

@@ -0,0 +1,895 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewComboBoxExCell : DataGridViewTextBoxCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewComboBoxExEditingControl)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewComboBoxExEditingControl ctl =
(DataGridViewComboBoxExEditingControl) DataGridView.EditingControl;
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn) OwningColumn;
ComboBoxEx cb = oc.ComboBoxEx;
ctl.DropDownStyle = cb.DropDownStyle;
ctl.AutoCompleteCustomSource = cb.AutoCompleteCustomSource;
ctl.AutoCompleteMode = cb.AutoCompleteMode;
ctl.AutoCompleteSource = cb.AutoCompleteSource;
ctl.DrawMode = cb.DrawMode;
ctl.DropDownHeight = cb.DropDownHeight;
ctl.Enabled = cb.Enabled;
ctl.FlatStyle = cb.FlatStyle;
ctl.FocusCuesEnabled = cb.FocusCuesEnabled;
ctl.FormatString = cb.FormatString;
ctl.FormattingEnabled = cb.FormattingEnabled;
ctl.Images = cb.Images;
ctl.ImeMode = cb.ImeMode;
ctl.IntegralHeight = cb.IntegralHeight;
ctl.IsStandalone = cb.IsStandalone;
ctl.ItemHeight = cb.ItemHeight;
ctl.MaxDropDownItems = cb.MaxDropDownItems;
ctl.MaxLength = cb.MaxLength;
ctl.RenderBorder = cb.RenderBorder;
ctl.RightToLeft = cb.RightToLeft;
ctl.Style = cb.Style;
ctl.WatermarkBehavior = cb.WatermarkBehavior;
ctl.WatermarkColor = cb.WatermarkColor;
ctl.WatermarkEnabled = cb.WatermarkEnabled;
ctl.WatermarkFont = cb.WatermarkFont;
ctl.WatermarkText = cb.WatermarkText;
ctl.DataSource = cb.DataSource;
if (ctl.DataSource is List<string> == false)
ctl.ValueMember = cb.ValueMember;
ctl.DisplayMember = cb.DisplayMember;
if (ctl.DataSource == null)
{
object[] items = new object[cb.Items.Count];
cb.Items.CopyTo(items, 0);
ctl.Items.Clear();
ctl.Items.AddRange(items);
ctl.Text = Convert.ToString(initialFormattedValue);
}
else
{
object o = GetValue(rowIndex);
object value = GetDataSourceValueEx(oc, cb, o);
if (value == null)
{
ctl.SelectedIndex = -1;
ctl.SelectedIndex = -1;
}
else
{
ctl.SelectedItem = value;
}
}
ctl.Click += Click;
ctl.DrawItem += DrawItem;
ctl.DropDownChange += DropDownChange;
ctl.MeasureItem += MeasureItem;
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewComboBoxExEditingControl cb =
DataGridView.EditingControl as DataGridViewComboBoxExEditingControl;
if (cb != null)
{
cb.Click -= Click;
cb.DrawItem -= DrawItem;
cb.DropDownChange -= DropDownChange;
cb.MeasureItem -= MeasureItem;
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region Click
/// <summary>
/// Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Click(object sender, EventArgs e)
{
((DataGridViewComboBoxExColumn)OwningColumn).DoComboBoxEx_Click(sender, e);
}
#endregion
#region DrawItem
/// <summary>
/// DrawItem
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void DrawItem(object sender, DrawItemEventArgs e)
{
((DataGridViewComboBoxExColumn)OwningColumn).DoComboBoxEx_DrawItem(sender, e);
}
#endregion
#region DropDownChange
/// <summary>
/// DropDownChange
/// </summary>
/// <param name="sender"></param>
/// <param name="expanded"></param>
void DropDownChange(object sender, bool expanded)
{
((DataGridViewComboBoxExColumn)OwningColumn).DoComboBoxEx_DropDownChange(
sender, new DropDownChangeEventArgs(RowIndex, ColumnIndex, expanded));
}
#endregion
#region MeasureItem
/// <summary>
/// MeasureItem
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void MeasureItem(object sender, MeasureItemEventArgs e)
{
((DataGridViewComboBoxExColumn)OwningColumn).DoComboBoxEx_MeasureItem(sender, e);
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
DataGridViewComboBoxExColumn oc = OwningColumn as DataGridViewComboBoxExColumn;
if (oc != null)
{
ComboBoxEx cb = oc.ComboBoxEx;
preferredSize.Height = cb.Height;
if (constraintSize.Width == 0)
{
Rectangle r = DataGridView.GetCellDisplayRectangle(ColumnIndex, rowIndex, true);
preferredSize.Width += cb.GetThumbRect(r).Width;
}
}
return (preferredSize);
}
#endregion
#endregion
#region ParseFormattedValue
/// <summary>
/// ParseFormattedValue
/// </summary>
/// <param name="formattedValue"></param>
/// <param name="cellStyle"></param>
/// <param name="formattedValueTypeConverter"></param>
/// <param name="valueTypeConverter"></param>
/// <returns></returns>
public override object ParseFormattedValue(object formattedValue,
DataGridViewCellStyle cellStyle, TypeConverter formattedValueTypeConverter, TypeConverter valueTypeConverter)
{
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn)OwningColumn;
ComboBoxEx di = oc.ComboBoxEx;
if (di.DataSource != null)
return (GetDataSourceValue(oc, di, formattedValue));
return (base.ParseFormattedValue(formattedValue,
cellStyle, formattedValueTypeConverter, valueTypeConverter));
}
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, value, cellStyle, paintParts, bm);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
private BindingContext _BindingContext = new BindingContext();
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="bm"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Bitmap bm)
{
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn)OwningColumn;
ComboBoxEx di = oc.ComboBoxEx;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
if (di.DataSource == null)
{
di.DisplayMember = "Text";
di.ValueMember = null;
}
else
{
value = GetDataSourceDisplayValue(oc, di, value);
di.BindingContext = _BindingContext;
}
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = cellStyle.BackColor;
string s = (value == Convert.DBNull ||
string.IsNullOrEmpty(Convert.ToString(value))) ? null : Convert.ToString(value);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, r, bm, g, oc, s);
else
DrawText(di, r, g, s);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="bm"></param>
/// <param name="g"></param>
/// <param name="oc"></param>
/// <param name="s"></param>
private void DrawControl(ComboBoxEx di, Rectangle r,
Bitmap bm, Graphics g, DataGridViewComboBoxExColumn oc, string s)
{
Rectangle t = di.GetThumbRect(new Rectangle(0, 0, r.Width, r.Height));
if (t.IsEmpty == false)
{
// Work around Windows XP and Windows DropDownList
// DrawToBitmap problems
if (MustRenderVisibleControl(di.DropDownStyle) == true)
{
di.Location = oc.DataGridView.Location;
if (di.Parent == null)
{
Form form = oc.DataGridView.FindForm();
if (form != null)
di.Parent = form;
}
di.SendToBack();
di.Visible = true;
}
using (Bitmap bm2 = new Bitmap(bm))
{
di.Bounds = r;
di.DrawToBitmap(bm2, r);
t.X += r.X;
t.Y += r.Y;
g.DrawImage(bm2, t, t, GraphicsUnit.Pixel);
if (t.Left < r.Right)
r.Width -= (r.Right - t.Left - 3);
}
di.Visible = false;
}
DrawText(di, r, g, s);
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="s"></param>
private void DrawText(ComboBoxEx di, Rectangle r, Graphics g, string s)
{
r.Inflate(-2, 0);
TextDrawing.DrawString(g, s, di.Font, di.ForeColor, r,
eTextFormat.VerticalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
}
#endregion
#region GetDataSource
#region GetDataSourceDisplayValue
private object GetDataSourceDisplayValue(
DataGridViewComboBoxExColumn oc, ComboBoxEx di, object key)
{
if (key != null &&
string.IsNullOrEmpty(di.ValueMember) == false &&
string.IsNullOrEmpty(di.DisplayMember) == false)
{
CurrencyManager cm = GetCurrencyManager(oc, di);
if (cm != null)
{
string t = key.ToString();
for (int i = 0; i < cm.List.Count; i++)
{
if (cm.List[i] is DataRowView)
{
DataRowView drView = (DataRowView) cm.List[i];
string s = drView[di.ValueMember].ToString();
if (t.Equals(s) == true)
return (drView[di.DisplayMember]);
}
else if (cm.List[i] is string)
{
if (t.Equals(cm.List[i]) == true)
return (key);
}
else
{
object o = cm.List[i];
object value = o.GetType().GetProperty(di.ValueMember).GetValue(o, null);
//if (value is string)
{
if (key.Equals(value) == true)
{
value = o.GetType().GetProperty(di.DisplayMember).GetValue(o, null);
return (value);
}
}
}
}
}
}
return ((key == Convert.DBNull) ? "" : key);
}
#endregion
#region GetDataSourceValueEx
private object GetDataSourceValueEx(
DataGridViewComboBoxExColumn oc, ComboBoxEx di, object key)
{
if (key != null &&
string.IsNullOrEmpty(di.ValueMember) == false &&
string.IsNullOrEmpty(di.DisplayMember) == false)
{
CurrencyManager cm = GetCurrencyManager(oc, di);
if (cm != null)
{
string t = key.ToString();
for (int i = 0; i < cm.List.Count; i++)
{
if (cm.List[i] is DataRowView)
{
DataRowView drView = (DataRowView)cm.List[i];
string s = drView[di.ValueMember].ToString();
if (t.Equals(s) == true)
return (drView);
}
else if (cm.List[i] is string)
{
if (t.Equals(cm.List[i]) == true)
return (key);
}
else
{
object o = cm.List[i];
object value = o.GetType().GetProperty(di.ValueMember).GetValue(o, null);
if (key.Equals(value) == true)
return (o);
}
}
}
}
return ((key == Convert.DBNull) ? null : key);
}
#endregion
#region GetDataSourceValue
private object GetDataSourceValue(
DataGridViewComboBoxExColumn oc, ComboBoxEx di, object key)
{
if (key != null &&
string.IsNullOrEmpty(di.ValueMember) == false &&
string.IsNullOrEmpty(di.DisplayMember) == false)
{
CurrencyManager cm = GetCurrencyManager(oc, di);
if (cm != null)
{
string t = key.ToString();
for (int i = 0; i < cm.List.Count; i++)
{
if (cm.List[i] is DataRowView)
{
DataRowView drView = (DataRowView) cm.List[i];
string s = drView[di.DisplayMember].ToString();
if (t.Equals(s) == true)
return (drView[di.ValueMember]);
}
else if (cm.List[i] is string)
{
if (t.Equals(cm.List[i]) == true)
return (key);
}
else
{
object o = cm.List[i];
object value = o.GetType().GetProperty(di.DisplayMember).GetValue(o, null);
if (value is string)
{
if (t.Equals(value) == true)
{
value = o.GetType().GetProperty(di.ValueMember).GetValue(o, null);
return (value);
}
}
}
}
}
}
return (key);
}
#endregion
#region GetCurrencyManager
private CurrencyManager GetCurrencyManager(
DataGridViewComboBoxExColumn oc, ComboBoxEx di)
{
if (oc.CurrencyManager == null)
{
if (DataGridView != null && DataGridView.BindingContext != null &&
di.DataSource != null && di.DataSource != Convert.DBNull)
{
oc.CurrencyManager = (CurrencyManager) DataGridView.BindingContext[di.DataSource];
}
}
return (oc.CurrencyManager);
}
#endregion
#endregion
#region MustRenderVisibleControl
/// <summary>
/// MustRenderVisibleControl
/// </summary>
/// <param name="style"></param>
/// <returns></returns>
private bool MustRenderVisibleControl(ComboBoxStyle style)
{
if (style == ComboBoxStyle.DropDownList)
return (true);
OperatingSystem osInfo = Environment.OSVersion;
return (osInfo.Platform == PlatformID.Win32Windows ||
(osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major < 6));
}
#endregion
#endregion
#endregion
#region Mouse support
#region OnMouseEnter
/// <summary>
/// OnMouseEnter
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseEnter(int rowIndex)
{
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn) OwningColumn;
ComboBoxEx di = oc.ComboBoxEx;
if (DataGridView != null)
{
if ((uint)RowIndex < DataGridView.Rows.Count)
{
if (di.DataSource != null)
this.ToolTipText = Convert.ToString(GetDataSourceDisplayValue(oc, di, Value));
else
this.ToolTipText = Convert.ToString(Value);
}
}
base.OnMouseEnter(rowIndex);
}
#endregion
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewComboBoxExColumn oc = (DataGridViewComboBoxExColumn)OwningColumn;
Size size = oc.ComboBoxEx.Size;
cellBounds.Location = new Point(1, 1);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = Math.Min(size.Height, cellBounds.Height);
return (cellBounds);
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,954 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "Controls.ComboBoxEx.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewComboBoxExColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a ComboBox Cell is painted
/// </summary>
[Description("Occurs right before a ComboBox Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
/// <summary>
/// Occurs when the ComboBox is clicked
/// </summary>
[Description("Occurs when the ComboBox is clicked.")]
public event EventHandler<EventArgs> Click;
/// <summary>
/// Occurs when a visual aspect of an owner-drawn ComboBox changes
/// </summary>
[Description("Occurs when a visual aspect of an owner-drawn ComboBox changes.")]
public event EventHandler<DrawItemEventArgs> DrawItem;
/// <summary>
/// Occurs when drop down portion of the ComboBox is shown or hidden.
/// </summary>
[Description("Occurs when drop down portion of the ComboBox is shown or hidden.")]
public event EventHandler<DropDownChangeEventArgs> DropDownChange;
/// <summary>
/// Occurs each time an owner-drawn ComboBox item needs
/// to be drawn and when the sizes of the list items are determined
/// </summary>
[Description("Occurs each time an owner-drawn ComboBox item needs to be drawn and when the sizes of the list items are determined.")]
public event EventHandler<MeasureItemEventArgs> MeasureItem;
#endregion
#region Private variables
private ComboBoxEx _ComboBoxEx;
private Bitmap _CellBitmap;
private CurrencyManager _CurrencyManager;
private bool _DisplayControlForCurrentCellOnly = true;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewComboBoxExColumn()
{
CellTemplate = new DataGridViewComboBoxExCell();
_ComboBoxEx = new ComboBoxEx();
_ComboBoxEx.RenderBorder = false;
_ComboBoxEx.Visible = false;
HookEvents(true);
}
#region Internal properties
#region ComboBoxEx
/// <summary>
/// Gets the underlying ComboBoxEx control
/// </summary>
internal ComboBoxEx ComboBoxEx
{
get { return (_ComboBoxEx); }
}
#endregion
#region CurrencyManager
/// <summary>
/// Gets or sets the ComboBox CurrencyManager
/// </summary>
internal CurrencyManager CurrencyManager
{
get { return (_CurrencyManager); }
set { _CurrencyManager = value; }
}
#endregion
#endregion
#region Public properties
#region AutoCompleteCustomSource
/// <summary>
/// Gets or sets a custom System.Collections.Specialized.StringCollection
/// to use when the AutoCompleteSource property is set to CustomSource.
/// </summary>
[Browsable(true), DefaultValue(null)]
[Description("Gets or sets a custom Specialized.StringCollection to use when the AutoCompleteSource property is set to CustomSource.")]
public AutoCompleteStringCollection AutoCompleteCustomSource
{
get { return (_ComboBoxEx.AutoCompleteCustomSource); }
set { _ComboBoxEx.AutoCompleteCustomSource = value; }
}
#endregion
#region AutoCompleteMode
/// <summary>
/// Gets or sets an option that controls how automatic completion works for the ComboBox.
/// </summary>
[Browsable(true), DefaultValue(AutoCompleteMode.None)]
[Description("Indicates how automatic completion works for the ComboBox.")]
public AutoCompleteMode AutoCompleteMode
{
get { return (_ComboBoxEx.AutoCompleteMode); }
set { _ComboBoxEx.AutoCompleteMode = value; }
}
#endregion
#region AutoCompleteSource
/// <summary>
/// Gets or sets a value specifying the source of complete strings used for automatic completion.
/// </summary>
[Browsable(true), DefaultValue(AutoCompleteSource.None)]
[Description("Indicates the source of complete strings used for automatic completion.")]
public AutoCompleteSource AutoCompleteSource
{
get { return (_ComboBoxEx.AutoCompleteSource); }
set { _ComboBoxEx.AutoCompleteSource = value; }
}
#endregion
#region DataSource
/// <summary>
/// Gets or sets the data source that populates the selections for the combo box
/// </summary>
[Browsable(true), Category("Data"), DefaultValue((string)null)]
[AttributeProvider(typeof(IListSource))]
[Description("Indicates the data source that populates the selections for the combo box.")]
public object DataSource
{
get { return (_ComboBoxEx.DataSource); }
set
{
_ComboBoxEx.DataSource = value;
CurrencyManager = null;
}
}
#endregion
#region DisplayMember
/// <summary>
/// Gets or sets a string that specifies the property or column
/// from which to retrieve strings for display in the combo box.
/// </summary>
[Browsable(true), DefaultValue(""), Category("Data")]
[Description("Indicates a string that specifies the property or column from which to retrieve strings for display in the combo box")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string DisplayMember
{
get { return (_ComboBoxEx.DisplayMember); }
set { _ComboBoxEx.DisplayMember = value; }
}
#endregion
#region DisplayControlForCurrentCellOnly
/// <summary>
/// Gets or sets whether the control
/// will be displayed for the current cell only.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control will be displayed for the current cell only.")]
public bool DisplayControlForCurrentCellOnly
{
get { return (_DisplayControlForCurrentCellOnly); }
set
{
if (_DisplayControlForCurrentCellOnly != value)
{
_DisplayControlForCurrentCellOnly = value;
_ComboBoxEx.Invalidate();
}
}
}
#endregion
#region DrawMode
/// <summary>
/// Gets or sets a value indicating whether user code or
/// operating system code will handle drawing of elements in the list.
/// </summary>
[Browsable(true), DefaultValue(DrawMode.Normal)]
[Description("Indicates whether user code or operating system code will handle drawing of elements in the list.")]
public DrawMode DrawMode
{
get { return (_ComboBoxEx.DrawMode); }
set { _ComboBoxEx.DrawMode = value; }
}
#endregion
#region DropDownStyle
/// <summary>
/// Gets or sets a value specifying the style of the combo box.
/// </summary>
[Browsable(true), DefaultValue(ComboBoxStyle.DropDown)]
[Description("Indicates the style of the combo box.")]
public ComboBoxStyle DropDownStyle
{
get { return (_ComboBoxEx.DropDownStyle); }
set { _ComboBoxEx.DropDownStyle = value; }
}
#endregion
#region DropDownHeight
/// <summary>
/// Gets or sets the height in pixels of the drop-down portion of the ComboBox.
/// </summary>
[Browsable(true), DefaultValue(100)]
[Description("Indicates the height in pixels of the drop-down portion of the ComboBox.")]
public int DropDownHeight
{
get { return (_ComboBoxEx.DropDownHeight); }
set { _ComboBoxEx.DropDownHeight = value; }
}
#endregion
#region DropDownWidth
/// <summary>
/// Gets or sets the width of the drop-down lists of the combo box.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(1)]
[Description("Indicates the width of the drop-down lists of the combo box")]
public int DropDownWidth
{
get { return (_ComboBoxEx.DropDownWidth); }
set { _ComboBoxEx.DropDownWidth = value; }
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_ComboBoxEx.Enabled); }
set { _ComboBoxEx.Enabled = value; }
}
#endregion
#region FlatStyle
/// <summary>
/// Gets or sets the flat style appearance of the column's cells.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(FlatStyle.Standard)]
[Description("Indicates the flat style appearance of the column's cells")]
public FlatStyle FlatStyle
{
get { return (_ComboBoxEx.FlatStyle); }
set { _ComboBoxEx.FlatStyle = value; }
}
#endregion
#region FocusCuesEnabled
/// <summary>
/// Gets or sets whether control displays focus cues when focused.
/// </summary>
[DefaultValue(true), Category("Behavior")]
[Description("Indicates whether control displays focus cues when focused.")]
public bool FocusCuesEnabled
{
get { return (_ComboBoxEx.FocusCuesEnabled); }
set { _ComboBoxEx.FocusCuesEnabled = value; }
}
#endregion
#region FormatString
/// <summary>
/// Gets or sets the format-specifier
/// characters that indicate how a value is to be displayed.
/// </summary>
[Browsable(true), DefaultValue("")]
[Description("Indicates the format-specifier characters that indicate how a value is to be displayed.")]
public string FormatString
{
get { return (_ComboBoxEx.FormatString); }
set { _ComboBoxEx.FormatString = value; }
}
#endregion
#region FormattingEnabled
/// <summary>
/// Gets or sets a value indicating whether formatting is applied to the DisplayMember property.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether formatting is applied to the DisplayMember.")]
public bool FormattingEnabled
{
get { return (_ComboBoxEx.FormattingEnabled); }
set { _ComboBoxEx.FormattingEnabled = value; }
}
#endregion
#region Images
/// <summary>
/// Gets or sets the ImageList control used by Combo box to draw images.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(null)]
[Description("The ImageList control used by Combo box to draw images.")]
public ImageList Images
{
get { return (_ComboBoxEx.Images); }
set { _ComboBoxEx.Images = value; }
}
#endregion
#region ImeMode
/// <summary>
/// Gets or sets the Input Method Editor (IME) mode of the control.
/// </summary>
[Browsable(true), DefaultValue(ImeMode.Inherit)]
[Description("Indicates the Input Method Editor (IME) mode of the control.")]
public ImeMode ImeMode
{
get { return (_ComboBoxEx.ImeMode); }
set { _ComboBoxEx.ImeMode = value; }
}
#endregion
#region IntegralHeight
/// <summary>
/// Gets or sets a value indicating whether
/// the control should resize to avoid showing partial items.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether the control should resize to avoid showing partial items.")]
public bool IntegralHeight
{
get { return (_ComboBoxEx.IntegralHeight); }
set { _ComboBoxEx.IntegralHeight = value; }
}
#endregion
#region IsStandalone
/// <summary>
/// Gets or sets whether control is stand-alone control.
/// Stand-alone flag affects the appearance of the control in Office 2007 style.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates the appearance of the control.")]
public bool IsStandalone
{
get { return (_ComboBoxEx.IsStandalone); }
set { _ComboBoxEx.IsStandalone = value; }
}
#endregion
#region ItemHeight
/// <summary>
/// Gets or sets the height of an item in the combo box.
/// </summary>
[Browsable(true), DefaultValue(12)]
[Description("Indicates the height of an item in the combo box.")]
public int ItemHeight
{
get { return (_ComboBoxEx.ItemHeight); }
set { _ComboBoxEx.ItemHeight = value; }
}
#endregion
#region Items
/// <summary>
/// Gets the collection of objects used as selections in the combo box.
/// </summary>
[Browsable(true), Category("Data")]
[Description("Indicates the collection of objects used as selections in the combo box")]
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ComboBox.ObjectCollection Items
{
get { return (_ComboBoxEx.Items); }
}
#endregion
#region MaxDropDownItems
/// <summary>
/// Gets or sets the maximum number of items
/// in the drop-down list of the cells in the column.
/// </summary>
[Browsable(true), DefaultValue(8), Category("Behavior")]
[Description("Indicates the maximum number of items in the drop-down list of the cells in the column.")]
public int MaxDropDownItems
{
get { return (_ComboBoxEx.MaxDropDownItems); }
set { _ComboBoxEx.MaxDropDownItems = value; }
}
#endregion
#region MaxLength
/// <summary>
/// Gets or sets the number of characters a user can type into the ComboBox.
/// </summary>
[Browsable(true), DefaultValue(0)]
[Description("Indicates the number of characters a user can type into the ComboBox.")]
public int MaxLength
{
get { return (_ComboBoxEx.MaxLength); }
set { _ComboBoxEx.MaxLength = value; }
}
#endregion
#region RightToLeft
/// <summary>
/// Gets or sets a value indicating whether control's
/// elements are aligned to support locales using right-to-left fonts.
/// </summary>
[Browsable(true), DefaultValue(RightToLeft.Inherit)]
[Description("Indicates control's elements are aligned to support locales using right-to-left fonts.")]
public RightToLeft RightToLeft
{
get { return (_ComboBoxEx.RightToLeft); }
set { _ComboBoxEx.RightToLeft = value; }
}
#endregion
#region Sorted
/// <summary>
/// Gets or sets whether the items in the combo box are sorted.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Behavior")]
[Description("Indicates whether the items in the combo box are sorted.")]
public bool Sorted
{
get { return (_ComboBoxEx.Sorted); }
set { _ComboBoxEx.Sorted = value; }
}
#endregion
#region Style
/// <summary>
/// Determines the visual style applied to
/// the combo box when shown. Default style is Office 2007.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(eDotNetBarStyle.Office2007)]
[Description("Determines the display of the item when shown.")]
public eDotNetBarStyle Style
{
get { return (_ComboBoxEx.Style); }
set { _ComboBoxEx.Style = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text associated with this control.
/// </summary>
[Browsable(true), DefaultValue("")]
[Description("Indicates the text associated with this control.")]
public string Text
{
get { return (_ComboBoxEx.Text); }
set { _ComboBoxEx.Text = value; }
}
#endregion
#region ValueMember
/// <summary>
/// Gets or sets a string that specifies the property or column
/// from which to get values that correspond to the selections in the drop-down list.
/// </summary>
[Browsable(true), Category("Data"), DefaultValue("")]
[Description("Indicates a string that specifies the property or column from which to get values that correspond to the selections in the drop-down list.")]
[Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version= 2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string ValueMember
{
get { return (_ComboBoxEx.ValueMember); }
set { _ComboBoxEx.ValueMember = value; }
}
#endregion
#region WatermarkBehavior
/// <summary>
/// Gets or sets the watermark hiding behaviour. Default value
/// indicates that watermark is hidden when control receives input focus.
/// </summary>
[DefaultValue(eWatermarkBehavior.HideOnFocus), Category("Behavior")]
[Description("Indicates watermark hiding behaviour.")]
public eWatermarkBehavior WatermarkBehavior
{
get { return (_ComboBoxEx.WatermarkBehavior); }
set { _ComboBoxEx.WatermarkBehavior = value; }
}
#endregion
#region WatermarkColor
/// <summary>
/// Gets or sets the watermark text color.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates watermark text color.")]
public Color WatermarkColor
{
get { return (_ComboBoxEx.WatermarkColor); }
set { _ComboBoxEx.WatermarkColor = value; }
}
/// <summary>
/// Indicates whether property should be serialized by Windows Forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeWatermarkColor()
{
return (_ComboBoxEx.ShouldSerializeWatermarkColor());
}
/// <summary>
/// Resets the property to default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetWatermarkColor()
{
_ComboBoxEx.ResetWatermarkColor();
}
#endregion
#region WatermarkEnabled
/// <summary>
/// Gets or sets whether watermark text is
/// displayed when control is empty. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether watermark text is displayed when control is empty.")]
public virtual bool WatermarkEnabled
{
get { return (_ComboBoxEx.WatermarkEnabled); }
set { _ComboBoxEx.WatermarkEnabled = value; }
}
#endregion
#region WatermarkFont
/// <summary>
/// Gets or sets the watermark font.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates watermark font.")]
public Font WatermarkFont
{
get { return (_ComboBoxEx.WatermarkFont); }
set { _ComboBoxEx.WatermarkFont = value; }
}
#endregion
#region WatermarkText
/// <summary>
/// Gets or sets the watermark (tip) text displayed inside of the control when Text
/// is not set and control does not have input focus. This property supports text-markup.
/// Note that WatermarkText is not compatible with the auto-complete feature of .NET Framework 2.0.
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates watermark text displayed inside of the control when Text is not set and control does not have input focus.")]
[Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(UITypeEditor))]
public string WatermarkText
{
get { return (_ComboBoxEx.WatermarkText); }
set { _ComboBoxEx.WatermarkText = value; }
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// HookEvents
/// </summary>
/// <param name="hook"></param>
private void HookEvents(bool hook)
{
if (hook == true)
_ComboBoxEx.DataSourceChanged += ComboBoxEx_DataSourceChanged;
else
_ComboBoxEx.DataSourceChanged -= ComboBoxEx_DataSourceChanged;
}
#endregion
#region Event processing
#region ComboBoxEx_DataSourceChanged
/// <summary>
/// ComboBoxEx_DataSourceChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ComboBoxEx_DataSourceChanged(object sender, EventArgs e)
{
_CurrencyManager = null;
_ComboBoxEx.Items.Clear();
_ComboBoxEx.DisplayMember = null;
_ComboBoxEx.ValueMember = null;
}
#endregion
#region DoComboBoxEx_Click
/// <summary>
/// DoComboBoxEx_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoComboBoxEx_Click(object sender, EventArgs e)
{
if (Click != null)
Click(sender, e);
}
#endregion
#region DoComboBoxEx_DrawItem
/// <summary>
/// DoComboBoxEx_DrawItem
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoComboBoxEx_DrawItem(object sender, DrawItemEventArgs e)
{
if (DrawItem != null)
DrawItem(sender, e);
}
#endregion
#region DoComboBoxEx_DropDownChange
/// <summary>
/// DoComboBoxEx_DropDownChange
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoComboBoxEx_DropDownChange(object sender, DropDownChangeEventArgs e)
{
if (DropDownChange != null)
DropDownChange(sender, e);
}
#endregion
#region DoComboBoxEx_MeasureItem
/// <summary>
/// DoComboBoxEx_MeasureItem
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoComboBoxEx_MeasureItem(object sender, MeasureItemEventArgs e)
{
if (MeasureItem != null)
MeasureItem(sender, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ToString
public override string ToString()
{
StringBuilder builder = new StringBuilder();
builder.Append("DataGridViewComboBoxExColumn { Name=");
builder.Append(Name);
builder.Append(", Index=");
builder.Append(Index.ToString(CultureInfo.CurrentCulture));
builder.Append(" }");
return (builder.ToString());
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewComboBoxExColumn cb = base.Clone() as DataGridViewComboBoxExColumn;
if (cb != null)
{
cb.AutoCompleteCustomSource = AutoCompleteCustomSource;
cb.AutoCompleteMode = AutoCompleteMode;
cb.AutoCompleteSource = AutoCompleteSource;
cb.DrawMode = DrawMode;
cb.DropDownHeight = DropDownHeight;
cb.DropDownStyle = DropDownStyle;
cb.Enabled = Enabled;
cb.FlatStyle = FlatStyle;
cb.FocusCuesEnabled = FocusCuesEnabled;
cb.FormatString = FormatString;
cb.FormattingEnabled = FormattingEnabled;
cb.Images = Images;
cb.ImeMode = ImeMode;
cb.IntegralHeight = IntegralHeight;
cb.IsStandalone = IsStandalone;
cb.ItemHeight = ItemHeight;
cb.MaxDropDownItems = MaxDropDownItems;
cb.MaxLength = MaxLength;
cb.RightToLeft = RightToLeft;
cb.Style = Style;
cb.Text = Text;
cb.WatermarkBehavior = WatermarkBehavior;
cb.WatermarkColor = WatermarkColor;
cb.WatermarkEnabled = WatermarkEnabled;
cb.WatermarkFont = WatermarkFont;
cb.WatermarkText = WatermarkText;
cb.DataSource = DataSource;
cb.DisplayMember = DisplayMember;
cb.ValueMember = ValueMember;
if (cb.DataSource == null)
{
for (int i = 0; i < Items.Count; i++)
cb.Items.Add(Items[i]);
}
cb.DisplayControlForCurrentCellOnly = DisplayControlForCurrentCellOnly;
}
return (cb);
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
HookEvents(false);
if (disposing == true)
_ComboBoxEx.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
}
#region DropDownChangeEventArgs
/// <summary>
/// DropDownChangeEventArgs
/// </summary>
public class DropDownChangeEventArgs : EventArgs
{
#region Private variables
private int _RowIndex;
private int _ColumnIndex;
private bool _Expanded;
#endregion
public DropDownChangeEventArgs(int rowIndex, int columnIndex, bool expanded)
{
_RowIndex = rowIndex;
_ColumnIndex = columnIndex;
_Expanded = expanded;
}
#region Public properties
/// <summary>
/// ColumnIndex
/// </summary>
public int ColumnIndex
{
get { return (_ColumnIndex); }
}
/// <summary>
/// Expanded state
/// </summary>
public bool Expanded
{
get { return (_Expanded); }
}
/// <summary>
/// RowIndex
/// </summary>
public int RowIndex
{
get { return (_RowIndex); }
}
#endregion
}
#endregion
}

View File

@@ -0,0 +1,240 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewComboBoxExEditingControl : ComboBoxEx, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
#endregion
public DataGridViewComboBoxExEditingControl()
{
TabStop = false;
}
#region OnTextChanged
/// <summary>
/// Handles OnTextChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(EventArgs e)
{
NotifyDataGridViewOfValueChange();
base.OnTextChanged(e);
}
#endregion
#region OnSelectedIndexChanged
/// <summary>
/// OnSelectedIndexChanged
/// </summary>
/// <param name="e"></param>
protected override void OnSelectedIndexChanged(EventArgs e)
{
base.OnSelectedIndexChanged(e);
if (SelectedIndex != -1)
NotifyDataGridViewOfValueChange();
}
/// <summary>
/// NotifyDataGridViewOfValueChange
/// </summary>
private void NotifyDataGridViewOfValueChange()
{
if (_DataGridView.EditingControl == this)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
}
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set { _DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get { return (GetEditingControlFormattedValue(DataGridViewDataErrorContexts.Formatting)); }
set
{
string s = value as string;
if (s != null)
{
Text = s;
if (string.Compare(s, this.Text, true, CultureInfo.CurrentCulture) != 0)
SelectedIndex = -1;
}
}
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (Cursors.Default); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
ForeColor = dataGridViewCellStyle.ForeColor;
BackColor = dataGridViewCellStyle.BackColor;
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (Text);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if (DroppedDown == false)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
}
if (((((keyData & Keys.KeyCode) != Keys.Down) && ((keyData & Keys.KeyCode) != Keys.Up)) &&
(!DroppedDown || ((keyData & Keys.KeyCode) != Keys.Escape))) && ((keyData & Keys.KeyCode) != Keys.Return))
{
return (dataGridViewWantsInputKey == false);
}
return (true);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
if (selectAll)
SelectAll();
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,746 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Media;
using System.Windows.Forms;
using DevComponents.Editors;
using DevComponents.Editors.DateTimeAdv;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewDateTimeInputCell : DataGridViewTextBoxCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewDateTimeInputEditingControl)); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof(string)); }
}
#endregion
#region ValueType
public override Type ValueType
{
get { return (typeof(DateTime)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewDateTimeInputEditingControl ctl =
(DataGridViewDateTimeInputEditingControl)DataGridView.EditingControl;
DataGridViewDateTimeInputColumn oc = OwningColumn as DataGridViewDateTimeInputColumn;
if (oc != null)
{
DateTimeInput di = oc.DateTimeInput;
ctl.AllowEmptyState = di.AllowEmptyState;
ctl.AutoAdvance = di.AutoAdvance;
ctl.AutoOverwrite = di.AutoOverwrite;
ctl.AutoSelectDate = di.AutoSelectDate;
ctl.CustomFormat = di.CustomFormat;
ctl.DefaultInputValues = di.DefaultInputValues;
ctl.Enabled = di.Enabled;
ctl.Format = di.Format;
ctl.InputHorizontalAlignment = GetHorizontalAlignment(dataGridViewCellStyle.Alignment);
ctl.IsInputReadOnly = di.IsInputReadOnly;
ctl.LockUpdateChecked = di.LockUpdateChecked;
ctl.MinDate = di.MinDate;
ctl.MaxDate = di.MaxDate;
ctl.SelectNextInputCharacters = di.SelectNextInputCharacters;
ctl.ShowCheckBox = di.ShowCheckBox;
ctl.ShowUpDown = di.ShowUpDown;
ctl.BackgroundStyle.ApplyStyle(di.BackgroundStyle);
ctl.BackgroundStyle.Class = di.BackgroundStyle.Class;
di.ButtonClear.CopyToItem(ctl.ButtonClear);
di.ButtonDropDown.CopyToItem(ctl.ButtonDropDown);
di.ButtonFreeText.CopyToItem(ctl.ButtonFreeText);
di.ButtonCustom.CopyToItem(ctl.ButtonCustom);
di.ButtonCustom2.CopyToItem(ctl.ButtonCustom2);
di.MonthCalendar.InternalCopyToItem(ctl.MonthCalendar);
ctl.ButtonClearClick += ButtonClearClick;
ctl.ButtonCustomClick += ButtonCustomClick;
ctl.ButtonCustom2Click += ButtonCustom2Click;
ctl.ButtonDropDownClick += ButtonDropDownClick;
ctl.ButtonFreeTextClick += ButtonFreeTextClick;
ctl.ConvertFreeTextEntry += ConvertFreeTextEntry;
//ctl.Value = GetValue(initialFormattedValue);
ctl.ValueObject = Value;
ctl.EditCancelled = false;
}
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewDateTimeInputEditingControl di =
DataGridView.EditingControl as DataGridViewDateTimeInputEditingControl;
if (di != null)
{
di.ButtonClearClick -= ButtonClearClick;
di.ButtonCustomClick -= ButtonCustomClick;
di.ButtonCustom2Click -= ButtonCustom2Click;
di.ButtonDropDownClick -= ButtonDropDownClick;
di.ButtonFreeTextClick -= ButtonFreeTextClick;
di.ConvertFreeTextEntry -= ConvertFreeTextEntry;
if (di.EditCancelled == true)
{
di.EditCancelled = false;
SystemSounds.Beep.Play();
}
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region ButtonClearClick
/// <summary>
/// ButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClearClick(object sender, CancelEventArgs e)
{
((DataGridViewDateTimeInputColumn)OwningColumn).DoButtonClearClick(sender, e);
}
#endregion
#region ButtonCustomClick
/// <summary>
/// ButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustomClick(object sender, EventArgs e)
{
((DataGridViewDateTimeInputColumn)OwningColumn).DoButtonCustomClick(sender, e);
}
#endregion
#region ButtonCustom2Click
/// <summary>
/// ButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustom2Click(object sender, EventArgs e)
{
((DataGridViewDateTimeInputColumn)OwningColumn).DoButtonCustom2Click(sender, e);
}
#endregion
#region ButtonDropDownClick
/// <summary>
/// ButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonDropDownClick(object sender, CancelEventArgs e)
{
((DataGridViewDateTimeInputColumn)OwningColumn).DoButtonDropDownClick(sender, e);
}
#endregion
#region ButtonFreeTextClick
/// <summary>
/// ButtonFreeTextClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonFreeTextClick(object sender, CancelEventArgs e)
{
((DataGridViewDateTimeInputColumn)OwningColumn).DoButtonFreeTextClick(sender, e);
}
#endregion
#region ConvertFreeTextEntry
/// <summary>
/// ConvertFreeTextEntry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ConvertFreeTextEntry(object sender, FreeTextEntryConversionEventArgs e)
{
((DataGridViewDateTimeInputColumn)OwningColumn).DoConvertFreeTextEntry(sender, e);
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (cellStyle != null && r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
DataGridViewDateTimeInputColumn oc = OwningColumn as DataGridViewDateTimeInputColumn;
if (oc != null)
{
DateTimeInput dt = oc.DateTimeInput;
preferredSize.Width += 6;
preferredSize.Height = dt.Height;
if (constraintSize.Width == 0)
{
preferredSize.Width += GetImageWidth(dt.ButtonClear);
preferredSize.Width += GetImageWidth(dt.ButtonCustom);
preferredSize.Width += GetImageWidth(dt.ButtonCustom2);
preferredSize.Width += GetImageWidth(dt.ButtonDropDown);
preferredSize.Width += GetImageWidth(dt.ButtonFreeText);
if (dt.ShowUpDown == true)
preferredSize.Width += 16;
if (dt.ShowCheckBox == true)
preferredSize.Width += 16;
}
}
return (preferredSize);
}
#endregion
#region GetFormattedValue
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
DataGridViewDateTimeInputColumn oc = OwningColumn as DataGridViewDateTimeInputColumn;
if (oc != null)
{
DateTimeInput dt = oc.DateTimeInput;
dt.Value = GetValue(value);
return (dt.Text);
}
return (base.GetFormattedValue(value, rowIndex,
ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
}
#endregion
#region GetImageWidth
private int GetImageWidth(InputButtonSettings ibs)
{
if (ibs.Visible == true)
return (ibs.Image != null ? ibs.Image.Width : 16);
return (0);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewDateTimeInputColumn oc = (DataGridViewDateTimeInputColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, formattedValue, cellStyle, paintParts);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts)
{
DataGridViewDateTimeInputColumn oc = (DataGridViewDateTimeInputColumn)OwningColumn;
DateTimeInput di = oc.DateTimeInput;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.BackgroundStyle.TextColor = cellStyle.ForeColor;
di.BackgroundStyle.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.InputHorizontalAlignment = GetHorizontalAlignment(cellStyle.Alignment);
di.Value = GetValue(value);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, r, g);
else
DrawText(di, r, g);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawControl(DateTimeInput di, Rectangle r, Graphics g)
{
GraphicsState gs = g.Save();
try
{
g.TranslateTransform(r.X, r.Y);
di.Width = r.Width;
di.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
g.Restore(gs);
}
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawText(DateTimeInput di, Rectangle r, Graphics g)
{
r.Inflate(-2, 0);
eTextFormat tf = eTextFormat.VerticalCenter;
switch (di.InputHorizontalAlignment)
{
case eHorizontalAlignment.Center:
tf |= eTextFormat.HorizontalCenter;
break;
case eHorizontalAlignment.Right:
tf |= eTextFormat.Right;
break;
}
TextDrawing.DrawString(g, di.Text, di.Font, di.ForeColor, r, tf);
}
#endregion
#endregion
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewDateTimeInputColumn oc = (DataGridViewDateTimeInputColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewDateTimeInputColumn oc = (DataGridViewDateTimeInputColumn)OwningColumn;
Size size = oc.DateTimeInput.Size;
cellBounds.Location = new Point(1, 1);
cellBounds.Width = Math.Min(size.Width, cellBounds.Width);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = size.Height;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private DateTime GetValue(object value)
{
if (value == Convert.DBNull ||
(value is string && String.IsNullOrEmpty((string)value) == true))
{
return (DateTime.MinValue);
}
if (value is DateTime)
return (Convert.ToDateTime(value));
else if (value is string && DevComponents.Editors.DateTimeAdv.DateTimeInput.CurrentCulture != null)
{
System.DateTime d = new System.DateTime();
if (System.DateTime.TryParse(value.ToString(), DevComponents.Editors.DateTimeAdv.DateTimeInput.GetActiveCulture().DateTimeFormat,
System.Globalization.DateTimeStyles.None, out d))
return d;
}
return (Convert.ToDateTime(value));
}
#endregion
#region GetHorizontalAlignment
/// <summary>
/// GetHorizontalAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private eHorizontalAlignment GetHorizontalAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (eHorizontalAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (eHorizontalAlignment.Right);
default:
return (eHorizontalAlignment.Left);
}
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,750 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using DevComponents.Editors;
using DevComponents.Editors.DateTimeAdv;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "DateTimeInput.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewDateTimeInputColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a DateTimeInput Cell is painted
/// </summary>
[Description("Occurs right before a DateTimeInput Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
/// <summary>
/// Occurs when Clear button is clicked and allows you
/// to cancel the default action performed by the button
/// </summary>
[Description("Occurs when Clear button is clicked and allows you to cancel the default action performed by the button.")]
public event EventHandler<CancelEventArgs> ButtonClearClick;
/// <summary>
/// Occurs when ButtonCustom control is clicked
/// </summary>
[Description("Occurs when ButtonCustom control is clicked.")]
public event EventHandler<EventArgs> ButtonCustomClick;
/// <summary>
/// Occurs when ButtonCustom2 control is clicked
/// </summary>
[Description("Occurs when ButtonCustom2 control is clicked.")]
public event EventHandler<EventArgs> ButtonCustom2Click;
/// <summary>
/// Occurs when Drop-Down button that shows calendar
/// is clicked and allows you to cancel showing of the popup
/// </summary>
[Description("Occurs when Drop-Down button that shows calendar is clicked and allows you to cancel showing of the popup.")]
public event EventHandler<CancelEventArgs> ButtonDropDownClick;
/// <summary>
/// Occurs when Free-Text button is clicked
/// and allows you to cancel its default action
/// </summary>
[Description("Occurs when Free-Text button is clicked and allows you to cancel its default action.")]
public event EventHandler<CancelEventArgs> ButtonFreeTextClick;
/// <summary>
/// Occurs if Free-Text entry value is not natively recognized by
/// the control and provides you with opportunity to convert that
/// value to the value the control expects
/// </summary>
[Description("Occurs if Free-Text entry value is not natively recognized by the control and provides you with opportunity to convert that value to the value the control expects.")]
public event EventHandler<FreeTextEntryConversionEventArgs> ConvertFreeTextEntry;
#endregion
#region Private variables
private DateTimeInput _DateTimeInput;
private Bitmap _CellBitmap;
private bool _DisplayControlForCurrentCellOnly = true;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewDateTimeInputColumn()
{
CellTemplate = new DataGridViewDateTimeInputCell();
_DateTimeInput = new DateTimeInput();
_DateTimeInput.BackgroundStyle.Class = ElementStyleClassKeys.DataGridViewDateTimeBorderKey;
_DateTimeInput.Visible = false;
}
#region Dispose
protected override void Dispose(bool disposing)
{
if (disposing == true)
_DateTimeInput.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
#region Internal properties
#region DateTimeInput
/// <summary>
/// Gets the underlying DateTimeInput control
/// </summary>
internal DateTimeInput DateTimeInput
{
get { return (_DateTimeInput); }
}
#endregion
#endregion
#region Public properties
#region AllowEmptyState
/// <summary>
/// Gets or sets whether empty null/nothing state of the control is
/// allowed. Default value is true which means that IsEmpty property may
/// return true if input value is resets or ValueObject set to null/nothing.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether empty null/nothing state of the control is allowed.")]
public bool AllowEmptyState
{
get { return (_DateTimeInput.AllowEmptyState); }
set { _DateTimeInput.AllowEmptyState = value; }
}
#endregion
#region AutoAdvance
/// <summary>
/// Gets or sets whether input focus is automatically advanced
/// to next input field when input is complete in current one.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Behavior")]
[Description("Indicates whether input focus is automatically advanced to next input field when input is complete in current one.")]
public bool AutoAdvance
{
get { return (_DateTimeInput.AutoAdvance); }
set { _DateTimeInput.AutoAdvance = value; }
}
#endregion
#region AutoSelectDate
/// <summary>
/// Gets or sets whether first day in month is automatically
/// selected on popup date picker when month or year is changed.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Behavior")]
[Description("Indicates whether first day in month is automatically selected on popup date picker when month or year is changed.")]
public bool AutoSelectDate
{
get { return (_DateTimeInput.AutoSelectDate); }
set { _DateTimeInput.AutoSelectDate = value; }
}
#endregion
#region AutoOverwrite
/// <summary>
/// Gets or sets whether auto-overwrite functionality for input is enabled.
/// When in auto-overwrite mode input field will erase existing entry
/// and start new one if typing is continued after InputComplete method is called.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether auto-overwrite functionality for input is enabled.")]
public bool AutoOverwrite
{
get { return (_DateTimeInput.AutoOverwrite); }
set { _DateTimeInput.AutoOverwrite = value; }
}
#endregion
#region BackgroundStyle
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Browsable(true), Category("Style")]
[Description("Gets or sets control background style.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return (_DateTimeInput.BackgroundStyle); }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
_DateTimeInput.ResetBackgroundStyle();
_DateTimeInput.BackgroundStyle.Class = "TextBoxBorder";
_DateTimeInput.BackgroundStyle.CornerType = eCornerType.Square;
}
#endregion
#region ButtonClear
/// <summary>
/// Gets the object that describes the settings for the button
/// that clears the content of the control when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that clears the content of the control when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonClear
{
get { return (_DateTimeInput.ButtonClear); }
}
#endregion
#region ButtonCustom
/// <summary>
/// Gets the object that describes the settings for the custom button
/// that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom
{
get { return (_DateTimeInput.ButtonCustom); }
}
#endregion
#region ButtonCustom2
/// <summary>
/// Gets the object that describes the settings for the custom button that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom2
{
get { return (_DateTimeInput.ButtonCustom2); }
}
#endregion
#region ButtonDropDown
/// <summary>
/// Gets the object that describes the settings for the button
/// that shows drop-down when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that shows drop-down when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonDropDown
{
get { return (_DateTimeInput.ButtonDropDown); }
}
#endregion
#region ButtonFreeText
/// <summary>
/// Gets the object that describes the settings for the button
/// that switches the control into the free-text entry mode when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that switches the control into the free-text entry mode when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonFreeText
{
get { return (_DateTimeInput.ButtonFreeText); }
}
#endregion
#region CustomFormat
/// <summary>
/// Gets or sets the custom date/time format string.
/// </summary>
[Browsable(true), DefaultValue("")]
[Description("Indicates the custom date/time format string. "), Localizable(true)]
public string CustomFormat
{
get { return (_DateTimeInput.CustomFormat); }
set { _DateTimeInput.CustomFormat = value; }
}
#endregion
#region DisplayControlForCurrentCellOnly
/// <summary>
/// Gets or sets whether the control
/// will be displayed for the current cell only.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control will be displayed for the current cell only.")]
public bool DisplayControlForCurrentCellOnly
{
get { return (_DisplayControlForCurrentCellOnly); }
set
{
if (_DisplayControlForCurrentCellOnly != value)
{
_DisplayControlForCurrentCellOnly = value;
_DateTimeInput.Invalidate();
}
}
}
#endregion
#region DefaultInputValues
/// <summary>
/// Gets or sets whether empty input values (year, month or day) are
/// set to defaults while user is entering data. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether empty input values (year, month or day) are set to defaults while user is entering data")]
public bool DefaultInputValues
{
get { return (_DateTimeInput.DefaultInputValues); }
set { _DateTimeInput.DefaultInputValues = value; }
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_DateTimeInput.Enabled); }
set { _DateTimeInput.Enabled = value; }
}
#endregion
#region Format
/// <summary>
/// Gets or sets the format date/time is displayed in. To specify
/// custom format set this value to Custom and specify custom format
/// using CustomFormat property.
/// </summary>
[Browsable(true), DefaultValue(eDateTimePickerFormat.Short)]
[Description("Indicates the format date/time is displayed in. To specify custom format set this value to Custom and specify custom format using CustomFormat property.")]
public eDateTimePickerFormat Format
{
get { return (_DateTimeInput.Format); }
set { _DateTimeInput.Format = value; }
}
#endregion
#region InputHorizontalAlignment
/// <summary>
/// Gets or sets the input field alignment inside the control
/// </summary>
[Browsable(true), DefaultValue(eHorizontalAlignment.Right), Category("Appearance")]
[Description("Indicates alignment of input fields inside of the control.")]
public eHorizontalAlignment InputHorizontalAlignment
{
get { return (_DateTimeInput.InputHorizontalAlignment); }
set { _DateTimeInput.InputHorizontalAlignment = value; }
}
#endregion
#region IsInputReadOnly
/// <summary>
/// Gets or sets whether input part of the control is read-only. When set
/// to true the input part of the control becomes read-only and does not allow
/// the typing. However, drop-down part if visible still allows user to change
/// the value of the control. Use this property to allow change of the value
/// through drop-down picker only.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether input part of the control is read-only.")]
public bool IsInputReadOnly
{
get { return (_DateTimeInput.IsInputReadOnly); }
set { _DateTimeInput.IsInputReadOnly = value; }
}
#endregion
#region LockUpdateChecked
/// <summary>
/// Gets or sets whether check box shown using ShowCheckBox
/// property which locks/unlocks the control update is checked.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether check box shown using ShowCheckBox property which locks/unlocks the control update is checked.")]
public bool LockUpdateChecked
{
get { return (_DateTimeInput.LockUpdateChecked); }
set { _DateTimeInput.LockUpdateChecked = value; }
}
#endregion
#region MaxDate
/// <summary>
/// Gets or sets the maximum date and time that can be selected in the control.
/// </summary>
[Browsable(true)]
[Description("Indicates maximum date and time that can be selected in the control.")]
public DateTime MaxDate
{
get { return (_DateTimeInput.MaxDate); }
set { _DateTimeInput.MaxDate = value; }
}
/// <summary>
/// Gets whether Value property should be serialized by Windows Forms designer.
/// </summary>
/// <returns>true if value serialized otherwise false.</returns>
public bool ShouldSerializeMaxDate()
{
return (MaxDate.Equals(DateTimeGroup.MaxDateTime) == false);
}
#endregion
#region MinDate
/// <summary>
/// Gets or sets the minimum date and time that can be selected in the control.
/// </summary>
[Browsable(true)]
[Description("Indicates minimum date and time that can be selected in the control.")]
public DateTime MinDate
{
get { return (_DateTimeInput.MinDate); }
set { _DateTimeInput.MinDate = value; }
}
/// <summary>
/// Gets whether Value property should be serialized by Windows Forms designer.
/// </summary>
/// <returns>true if value serialized otherwise false.</returns>
public bool ShouldSerializeMinDate()
{
return (MinDate.Equals(DateTimeGroup.MinDateTime) == false);
}
#endregion
#region MonthCalendar
/// <summary>
/// Gets the reference to the internal MonthCalendarItem control which is used to display calendar when drop-down is open.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("Gets the reference to the internal MonthCalendarAdv control which is used to display calendar when drop-down is open.")]
public MonthCalendarItem MonthCalendar
{
get { return (_DateTimeInput.MonthCalendar); }
}
#endregion
#region SelectNextInputCharacters
/// <summary>
/// List of characters that when pressed would select next input field. For example if you are
/// allowing time input you could set this property to : so when user presses the : character,
/// the input is forwarded to the next input field.
/// </summary>
[Browsable(true), DefaultValue(""), Category("Behavior")]
[Description("List of characters that when pressed would select next input field.")]
public string SelectNextInputCharacters
{
get { return (_DateTimeInput.SelectNextInputCharacters); }
set { _DateTimeInput.SelectNextInputCharacters = value; }
}
#endregion
#region ShowCheckBox
/// <summary>
/// Gets or sets a value indicating whether a check box is
/// displayed to the left of the input value. Set to true if a check box
/// is displayed to the left of the input value; otherwise, false. The default is false.
/// <remarks>
/// When the ShowCheckBox property is set to true, a check box is displayed
/// to the left of the input in the control. When the check box is selected, the value
/// can be updated. When the check box is cleared, the value is unable to be changed.
/// You can handle the LockUpdateChanged event to be notified when this check box is checked
/// and unchecked. Use LockUpdateChecked property to get or sets whether check box is checked.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether a check box is displayed to the left of the input value which allows locking of the control.")]
public bool ShowCheckBox
{
get { return (_DateTimeInput.ShowCheckBox); }
set { _DateTimeInput.ShowCheckBox = value; }
}
#endregion
#region ShowUpDown
/// <summary>
/// Gets or sets a value indicating whether a spin button control
/// (up-down control) is used to adjust the current value. The default is false.
/// <remarks>
/// When the ShowUpDown property is set to true, a spin button control
/// is shown to adjust value of currently focused input item. The value can
/// be adjusted by using the up and down buttons to change the value.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue(false)]
public bool ShowUpDown
{
get { return (_DateTimeInput.ShowUpDown); }
set { _DateTimeInput.ShowUpDown = value; }
}
#endregion
#endregion
#region Event processing
#region DoButtonClearClick
/// <summary>
/// DoButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonClearClick(object sender, CancelEventArgs e)
{
if (ButtonClearClick != null)
ButtonClearClick(this, e);
}
#endregion
#region DoButtonCustomClick
/// <summary>
/// DoButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustomClick(object sender, EventArgs e)
{
if (ButtonCustomClick != null)
ButtonCustomClick(this, e);
}
#endregion
#region DoButtonCustom2Click
/// <summary>
/// DoButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustom2Click(object sender, EventArgs e)
{
if (ButtonCustom2Click != null)
ButtonCustom2Click(this, e);
}
#endregion
#region DoButtonDropDownClick
/// <summary>
/// DoButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonDropDownClick(object sender, CancelEventArgs e)
{
if (ButtonDropDownClick != null)
ButtonDropDownClick(this, e);
}
#endregion
#region DoButtonFreeTextClick
/// <summary>
/// DoButtonFreeTextClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonFreeTextClick(object sender, CancelEventArgs e)
{
if (ButtonFreeTextClick != null)
ButtonFreeTextClick(this, e);
}
#endregion
#region DoConvertFreeTextEntry
/// <summary>
/// DoConvertFreeTextEntry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoConvertFreeTextEntry(object sender, FreeTextEntryConversionEventArgs e)
{
if (ConvertFreeTextEntry != null)
ConvertFreeTextEntry(this, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewDateTimeInputColumn dc = base.Clone() as DataGridViewDateTimeInputColumn;
if (dc != null)
{
dc.AllowEmptyState = AllowEmptyState;
dc.AutoAdvance = AutoAdvance;
dc.AutoOverwrite = AutoOverwrite;
dc.AutoSelectDate = AutoSelectDate;
dc.CustomFormat = CustomFormat;
dc.DefaultInputValues = DefaultInputValues;
dc.Enabled = Enabled;
dc.Format = Format;
dc.InputHorizontalAlignment = InputHorizontalAlignment;
dc.IsInputReadOnly = IsInputReadOnly;
dc.LockUpdateChecked = LockUpdateChecked;
dc.MinDate = MinDate;
dc.MaxDate = MaxDate;
dc.SelectNextInputCharacters = SelectNextInputCharacters;
dc.ShowCheckBox = ShowCheckBox;
dc.ShowUpDown = ShowUpDown;
dc.DisplayControlForCurrentCellOnly = DisplayControlForCurrentCellOnly;
DateTimeInput.MonthCalendar.InternalCopyToItem(dc.DateTimeInput.MonthCalendar);
dc.BackgroundStyle.ApplyStyle(DateTimeInput.BackgroundStyle);
dc.BackgroundStyle.Class = DateTimeInput.BackgroundStyle.Class;
DateTimeInput.ButtonClear.CopyToItem(dc.DateTimeInput.ButtonClear);
DateTimeInput.ButtonDropDown.CopyToItem(dc.DateTimeInput.ButtonDropDown);
DateTimeInput.ButtonFreeText.CopyToItem(dc.DateTimeInput.ButtonFreeText);
DateTimeInput.ButtonCustom.CopyToItem(dc.DateTimeInput.ButtonCustom);
DateTimeInput.ButtonCustom2.CopyToItem(dc.DateTimeInput.ButtonCustom2);
}
return (dc);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
}
}

View File

@@ -0,0 +1,218 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.Editors.DateTimeAdv;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewDateTimeInputEditingControl : DateTimeInput, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
private bool _EditCancelled;
#endregion
#region OnValueChanged
/// <summary>
/// Handles OnValueChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnValueChanged(EventArgs e)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(e);
}
#endregion
#region Internal properties
/// <summary>
/// Gets or sets the Edit state
/// </summary>
internal bool EditCancelled
{
get { return (_EditCancelled); }
set { _EditCancelled = value; }
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set { _DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get
{
DateTime date = Value;
if (date.Equals(DateTime.MinValue))
return (String.Empty);
return (this.Value.ToString());
}
set
{
string newValue = value as string;
if (newValue != null)
Value = DateTime.Parse(newValue);
}
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (base.Cursor); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
ForeColor = dataGridViewCellStyle.ForeColor;
BackColor = dataGridViewCellStyle.BackColor;
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (EditingControlFormattedValue);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
if ((keyData & Keys.Escape) == Keys.Escape)
_EditCancelled = true;
return (dataGridViewWantsInputKey == false);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,730 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Media;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewDoubleInputCell : DataGridViewTextBoxCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewDoubleInputEditingControl)); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof(string)); }
}
#endregion
#region ValueType
public override Type ValueType
{
get { return (typeof(double)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewDoubleInputEditingControl ctl =
(DataGridViewDoubleInputEditingControl)DataGridView.EditingControl;
DataGridViewDoubleInputColumn oc = OwningColumn as DataGridViewDoubleInputColumn;
if (oc != null)
{
DoubleInput di = oc.DoubleInput;
ctl.Value = GetValue(di.Value);
ctl.DisplayFormat = di.DisplayFormat;
ctl.Enabled = di.Enabled;
ctl.Increment = di.Increment;
ctl.LockUpdateChecked = di.LockUpdateChecked;
ctl.MaxValue = di.MaxValue;
ctl.MinValue = di.MinValue;
ctl.ShowCheckBox = di.ShowCheckBox;
ctl.ShowUpDown = di.ShowUpDown;
ctl.BackgroundStyle.ApplyStyle(di.BackgroundStyle);
ctl.BackgroundStyle.Class = di.BackgroundStyle.Class;
ctl.InputHorizontalAlignment = GetHorizontalAlignment(dataGridViewCellStyle.Alignment);
di.ButtonClear.CopyToItem(ctl.ButtonClear);
di.ButtonCustom.CopyToItem(ctl.ButtonCustom);
di.ButtonCustom2.CopyToItem(ctl.ButtonCustom2);
di.ButtonDropDown.CopyToItem(ctl.ButtonDropDown);
di.ButtonFreeText.CopyToItem(ctl.ButtonFreeText);
ctl.ButtonClearClick += ButtonClearClick;
ctl.ButtonCustomClick += ButtonCustomClick;
ctl.ButtonCustom2Click += ButtonCustom2Click;
ctl.ButtonDropDownClick += ButtonDropDownClick;
ctl.ButtonFreeTextClick += ButtonFreeTextClick;
ctl.ConvertFreeTextEntry += ConvertFreeTextEntry;
ctl.EditCancelled = false;
}
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewDoubleInputEditingControl di =
DataGridView.EditingControl as DataGridViewDoubleInputEditingControl;
if (di != null)
{
di.ButtonClearClick -= ButtonClearClick;
di.ButtonDropDownClick -= ButtonDropDownClick;
di.ButtonFreeTextClick -= ButtonFreeTextClick;
di.ButtonCustomClick -= ButtonCustomClick;
di.ButtonCustom2Click -= ButtonCustom2Click;
di.ConvertFreeTextEntry -= ConvertFreeTextEntry;
if (di.EditCancelled == true)
{
di.EditCancelled = false;
SystemSounds.Beep.Play();
}
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region ButtonClearClick
/// <summary>
/// ButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClearClick(object sender, CancelEventArgs e)
{
((DataGridViewDoubleInputColumn)OwningColumn).DoButtonClearClick(sender, e);
}
#endregion
#region ButtonCustomClick
/// <summary>
/// ButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustomClick(object sender, EventArgs e)
{
((DataGridViewDoubleInputColumn)OwningColumn).DoButtonCustomClick(sender, e);
}
#endregion
#region ButtonCustom2Click
/// <summary>
/// ButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustom2Click(object sender, EventArgs e)
{
((DataGridViewDoubleInputColumn)OwningColumn).DoButtonCustom2Click(sender, e);
}
#endregion
#region ButtonDropDownClick
/// <summary>
/// ButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonDropDownClick(object sender, CancelEventArgs e)
{
((DataGridViewDoubleInputColumn)OwningColumn).DoButtonDropDownClick(sender, e);
}
#endregion
#region ButtonFreeTextClick
/// <summary>
/// ButtonFreeTextClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonFreeTextClick(object sender, CancelEventArgs e)
{
((DataGridViewDoubleInputColumn)OwningColumn).DoButtonFreeTextClick(sender, e);
}
#endregion
#region ConvertFreeTextEntry
/// <summary>
/// ConvertFreeTextEntry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ConvertFreeTextEntry(object sender, FreeTextEntryConversionEventArgs e)
{
((DataGridViewDoubleInputColumn)OwningColumn).DoConvertFreeTextEntry(sender, e);
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (cellStyle != null && r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
DataGridViewDoubleInputColumn oc = OwningColumn as DataGridViewDoubleInputColumn;
if (oc != null)
{
DoubleInput di = oc.DoubleInput;
preferredSize.Height = di.Height;
if (constraintSize.Width == 0)
{
preferredSize.Width += GetImageWidth(di.ButtonClear);
preferredSize.Width += GetImageWidth(di.ButtonCustom);
preferredSize.Width += GetImageWidth(di.ButtonCustom2);
preferredSize.Width += GetImageWidth(di.ButtonDropDown);
preferredSize.Width += GetImageWidth(di.ButtonFreeText);
if (di.ShowUpDown == true)
preferredSize.Width += 16;
if (di.ShowCheckBox == true)
preferredSize.Width += 16;
}
}
return (preferredSize);
}
#endregion
#region GetFormattedValue
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
DataGridViewDoubleInputColumn oc = OwningColumn as DataGridViewDoubleInputColumn;
if (oc != null)
{
DoubleInput di = oc.DoubleInput;
di.Value = GetValue(value);
return (di.Text);
}
return (base.GetFormattedValue(value, rowIndex,
ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
}
#endregion
#region GetImageWidth
private int GetImageWidth(InputButtonSettings ibs)
{
if (ibs.Visible == true)
return (ibs.Image != null ? ibs.Image.Width : 16);
return (0);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewDoubleInputColumn oc = (DataGridViewDoubleInputColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, value, cellStyle, paintParts);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts)
{
DataGridViewDoubleInputColumn oc = (DataGridViewDoubleInputColumn)OwningColumn;
DoubleInput di = oc.DoubleInput;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.BackgroundStyle.TextColor = cellStyle.ForeColor;
di.BackgroundStyle.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.InputHorizontalAlignment = GetHorizontalAlignment(cellStyle.Alignment);
di.Value = GetValue(value);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, r, g);
else
DrawText(di, r, g);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawControl(DoubleInput di, Rectangle r, Graphics g)
{
GraphicsState gs = g.Save();
try
{
g.TranslateTransform(r.X, r.Y);
di.Width = r.Width;
di.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
g.Restore(gs);
}
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawText(DoubleInput di, Rectangle r, Graphics g)
{
r.Inflate(-2, 0);
eTextFormat tf = eTextFormat.VerticalCenter;
switch (di.InputHorizontalAlignment)
{
case eHorizontalAlignment.Center:
tf |= eTextFormat.HorizontalCenter;
break;
case eHorizontalAlignment.Right:
tf |= eTextFormat.Right;
break;
}
TextDrawing.DrawString(g, di.Text, di.Font, di.ForeColor, r, tf);
}
#endregion
#endregion
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewDoubleInputColumn oc = (DataGridViewDoubleInputColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewDoubleInputColumn oc = (DataGridViewDoubleInputColumn)OwningColumn;
Size size = oc.DoubleInput.Size;
cellBounds.Location = new Point(1, 1);
cellBounds.Width = Math.Min(size.Width, cellBounds.Width);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = size.Height;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private double GetValue(object value)
{
if (value == Convert.DBNull ||
(value is string && String.IsNullOrEmpty((string)value) == true))
{
return (0);
}
if (value is string)
{
string svalue = value.ToString();
return Convert.ToDouble(svalue.Replace(" ", ""));
}
return (Convert.ToDouble(value));
}
#endregion
#region GetHorizontalAlignment
/// <summary>
/// GetHorizontalAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private eHorizontalAlignment GetHorizontalAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (eHorizontalAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (eHorizontalAlignment.Right);
default:
return (eHorizontalAlignment.Left);
}
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,597 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "DoubleInput.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewDoubleInputColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a DoubleInput Cell is painted
/// </summary>
[Description("Occurs right before a DoubleInput Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
/// <summary>
/// Occurs when Clear button is clicked and allows you
/// to cancel the default action performed by the button
/// </summary>
[Description("Occurs when Clear button is clicked and allows you to cancel the default action performed by the button.")]
public event EventHandler<CancelEventArgs> ButtonClearClick;
/// <summary>
/// Occurs when ButtonCustom control is clicked
/// </summary>
[Description("Occurs when ButtonCustom control is clicked.")]
public event EventHandler<EventArgs> ButtonCustomClick;
/// <summary>
/// Occurs when ButtonCustom2 control is clicked
/// </summary>
[Description("Occurs when ButtonCustom2 control is clicked.")]
public event EventHandler<EventArgs> ButtonCustom2Click;
/// <summary>
/// Occurs when Drop-Down button that shows calendar
/// is clicked and allows you to cancel showing of the popup
/// </summary>
[Description("Occurs when Drop-Down button that shows calendar is clicked and allows you to cancel showing of the popup.")]
public event EventHandler<CancelEventArgs> ButtonDropDownClick;
/// <summary>
/// Occurs when Free-Text button is clicked
/// and allows you to cancel its default action
/// </summary>
[Description("Occurs when Free-Text button is clicked and allows you to cancel its default action.")]
public event EventHandler<CancelEventArgs> ButtonFreeTextClick;
/// <summary>
/// Occurs if Free-Text entry value is not natively recognized by
/// the control and provides you with opportunity to convert that
/// value to the value the control expects
/// </summary>
[Description("Occurs if Free-Text entry value is not natively recognized by the control and provides you with opportunity to convert that value to the value the control expects.")]
public event EventHandler<FreeTextEntryConversionEventArgs> ConvertFreeTextEntry;
#endregion
#region Private variables
private DoubleInput _DoubleInput;
private Bitmap _CellBitmap;
private bool _DisplayControlForCurrentCellOnly = true;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewDoubleInputColumn()
{
CellTemplate = new DataGridViewDoubleInputCell();
_DoubleInput = new DoubleInput();
_DoubleInput.BackgroundStyle.Class = ElementStyleClassKeys.DataGridViewNumericBorderKey;
_DoubleInput.Visible = false;
}
#region Internal properties
#region DoubleInput
/// <summary>
/// DoubleInput
/// </summary>
internal DoubleInput DoubleInput
{
get { return (_DoubleInput); }
}
#endregion
#endregion
#region Public properties
#region BackgroundStyle
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Browsable(true), Category("Style")]
[Description("Gets or sets control background style.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return (_DoubleInput.BackgroundStyle); }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
_DoubleInput.ResetBackgroundStyle();
_DoubleInput.BackgroundStyle.Class = "TextBoxBorder";
_DoubleInput.BackgroundStyle.CornerType = eCornerType.Square;
}
#endregion
#region ButtonClear
/// <summary>
/// Gets the object that describes the settings for the button
/// that clears the content of the control when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that clears the content of the control when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonClear
{
get { return (_DoubleInput.ButtonClear); }
}
#endregion
#region ButtonCustom
/// <summary>
/// Gets the object that describes the settings for the custom button
/// that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom
{
get { return (_DoubleInput.ButtonCustom); }
}
#endregion
#region ButtonCustom2
/// <summary>
/// Gets the object that describes the settings for the custom button that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom2
{
get { return (_DoubleInput.ButtonCustom2); }
}
#endregion
#region ButtonDropDown
/// <summary>
/// Gets the object that describes the settings for the button
/// that shows drop-down when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that shows drop-down when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonDropDown
{
get { return (_DoubleInput.ButtonDropDown); }
}
#endregion
#region ButtonFreeText
/// <summary>
/// Gets the object that describes the settings for the button
/// that switches the control into the free-text entry mode when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that switches the control into the free-text entry mode when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonFreeText
{
get { return (_DoubleInput.ButtonFreeText); }
}
#endregion
#region DisplayFormat
/// <summary>
/// Gets or sets the Numeric String Format that is used to format
/// the numeric value entered for display purpose. Read more about
/// available formats in MSDN under "Standard Numeric Format Strings"
/// and "Custom Numeric Format Strings" topics.
/// <remarks>
/// The format specified here indicates the format for display purpose
/// only, not for the input purpose. For example to display the number
/// in system Currency format set the DisplayFormat to 'C'.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue("")]
[Description("Indicates Numeric String Format that is used to format the numeric value entered for display purpose.")]
public string DisplayFormat
{
get { return (_DoubleInput.DisplayFormat); }
set { _DoubleInput.DisplayFormat = value; }
}
#endregion
#region DisplayControlForCurrentCellOnly
/// <summary>
/// Gets or sets whether the control
/// will be displayed for the current cell only.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control will be displayed for the current cell only.")]
public bool DisplayControlForCurrentCellOnly
{
get { return (_DisplayControlForCurrentCellOnly); }
set
{
if (_DisplayControlForCurrentCellOnly != value)
{
_DisplayControlForCurrentCellOnly = value;
_DoubleInput.Invalidate();
}
}
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_DoubleInput.Enabled); }
set { _DoubleInput.Enabled = value; }
}
#endregion
#region Increment
/// <summary>
/// Gets or sets the value to increment or decrement the value of the
/// control when the up or down buttons are clicked.
/// </summary>
[Browsable(true), DefaultValue(1)]
[Description("Indicates value to increment or decrement the value of the control when the up or down buttons are clicked. ")]
public double Increment
{
get { return (_DoubleInput.Increment); }
set { _DoubleInput.Increment = value; }
}
#endregion
#region InputHorizontalAlignment
/// <summary>
/// Gets or sets the input field alignment inside the control
/// </summary>
[Browsable(true), DefaultValue(eHorizontalAlignment.Right), Category("Appearance")]
[Description("Indicates alignment of input fields inside of the control.")]
public eHorizontalAlignment InputHorizontalAlignment
{
get { return (_DoubleInput.InputHorizontalAlignment); }
set { _DoubleInput.InputHorizontalAlignment = value; }
}
#endregion
#region LockUpdateChecked
/// <summary>
/// Gets or sets whether check box shown using ShowCheckBox
/// property which locks/unlocks the control update is checked.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether check box shown using ShowCheckBox property which locks/unlocks the control update is checked.")]
public bool LockUpdateChecked
{
get { return (_DoubleInput.LockUpdateChecked); }
set { _DoubleInput.LockUpdateChecked = value; }
}
#endregion
#region MaxValue
/// <summary>
/// Gets or sets the maximum value that can be entered.
/// </summary>
[Browsable(true), DefaultValue(double.MaxValue)]
[Description("Indicates maximum value that can be entered.")]
public double MaxValue
{
get { return (_DoubleInput.MaxValue); }
set { _DoubleInput.MaxValue = value; }
}
#endregion
#region MinValue
/// <summary>
/// Gets or sets the minimum value that can be entered.
/// </summary>
[Browsable(true), DefaultValue(double.MinValue)]
[Description("Indicates minimum value that can be entered.")]
public double MinValue
{
get { return (_DoubleInput.MinValue); }
set { _DoubleInput.MinValue = value; }
}
#endregion
#region ShowCheckBox
/// <summary>
/// Gets or sets a value indicating whether a check box is
/// displayed to the left of the input value. Set to true if a check box
/// is displayed to the left of the input value; otherwise, false. The default is false.
/// <remarks>
/// When the ShowCheckBox property is set to true, a check box is displayed
/// to the left of the input in the control. When the check box is selected, the value
/// can be updated. When the check box is cleared, the value is unable to be changed.
/// You can handle the LockUpdateChanged event to be notified when this check box is checked
/// and unchecked. Use LockUpdateChecked property to get or sets whether check box is checked.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether a check box is displayed to the left of the input value which allows locking of the control.")]
public bool ShowCheckBox
{
get { return (_DoubleInput.ShowCheckBox); }
set { _DoubleInput.ShowCheckBox = value; }
}
#endregion
#region ShowUpDown
/// <summary>
/// Gets or sets a value indicating whether a spin button control
/// (up-down control) is used to adjust the current value. The default is false.
/// <remarks>
/// When the ShowUpDown property is set to true, a spin button control
/// is shown to adjust value of currently focused input item. The value can
/// be adjusted by using the up and down buttons to change the value.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue(false)]
public bool ShowUpDown
{
get { return (_DoubleInput.ShowUpDown); }
set { _DoubleInput.ShowUpDown = value; }
}
#endregion
#endregion
#region Event processing
#region DoButtonClearClick
/// <summary>
/// DoButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonClearClick(object sender, CancelEventArgs e)
{
if (ButtonClearClick != null)
ButtonClearClick(this, e);
}
#endregion
#region DoButtonCustomClick
/// <summary>
/// DoButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustomClick(object sender, EventArgs e)
{
if (ButtonCustomClick != null)
ButtonCustomClick(this, e);
}
#endregion
#region DoButtonCustom2Click
/// <summary>
/// DoButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustom2Click(object sender, EventArgs e)
{
if (ButtonCustom2Click != null)
ButtonCustom2Click(this, e);
}
#endregion
#region DoButtonDropDownClick
/// <summary>
/// DoButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonDropDownClick(object sender, CancelEventArgs e)
{
if (ButtonDropDownClick != null)
ButtonDropDownClick(this, e);
}
#endregion
#region DoButtonFreeTextClick
/// <summary>
/// DoButtonFreeTextClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonFreeTextClick(object sender, CancelEventArgs e)
{
if (ButtonFreeTextClick != null)
ButtonFreeTextClick(this, e);
}
#endregion
#region DoConvertFreeTextEntry
/// <summary>
/// DoConvertFreeTextEntry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoConvertFreeTextEntry(object sender, FreeTextEntryConversionEventArgs e)
{
if (ConvertFreeTextEntry != null)
ConvertFreeTextEntry(this, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewDoubleInputColumn dc = base.Clone() as DataGridViewDoubleInputColumn;
if (dc != null)
{
dc.DisplayFormat = DisplayFormat;
dc.Enabled = Enabled;
dc.Increment = Increment;
dc.InputHorizontalAlignment = InputHorizontalAlignment;
dc.LockUpdateChecked = LockUpdateChecked;
dc.MaxValue = MaxValue;
dc.MinValue = MinValue;
dc.ShowCheckBox = ShowCheckBox;
dc.ShowUpDown = ShowUpDown;
dc.DisplayControlForCurrentCellOnly = DisplayControlForCurrentCellOnly;
dc.BackgroundStyle.ApplyStyle(DoubleInput.BackgroundStyle);
dc.BackgroundStyle.Class = DoubleInput.BackgroundStyle.Class;
DoubleInput.ButtonClear.CopyToItem(dc.DoubleInput.ButtonClear);
DoubleInput.ButtonDropDown.CopyToItem(dc.DoubleInput.ButtonDropDown);
DoubleInput.ButtonFreeText.CopyToItem(dc.DoubleInput.ButtonFreeText);
DoubleInput.ButtonCustom.CopyToItem(dc.DoubleInput.ButtonCustom);
DoubleInput.ButtonCustom2.CopyToItem(dc.DoubleInput.ButtonCustom2);
}
return (dc);
}
#endregion
#region Dispose
protected override void Dispose(bool disposing)
{
if (disposing == true)
_DoubleInput.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
}
}

View File

@@ -0,0 +1,211 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewDoubleInputEditingControl : DoubleInput, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
private bool _EditCancelled;
#endregion
#region OnValueChanged
/// <summary>
/// Handles OnValueChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnValueChanged(EventArgs e)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(e);
}
#endregion
#region Internal properties
/// <summary>
/// Gets or sets the Edit state
/// </summary>
internal bool EditCancelled
{
get { return (_EditCancelled); }
set { _EditCancelled = value; }
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set {_DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get { return (Value.ToString()); }
set
{
string newValue = value as string;
if (newValue != null)
Value = int.Parse(newValue);
}
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (base.Cursor); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
ForeColor = dataGridViewCellStyle.ForeColor;
BackColor = dataGridViewCellStyle.BackColor;
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (EditingControlFormattedValue);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
if ((keyData & Keys.Escape) == Keys.Escape)
_EditCancelled = true;
return (dataGridViewWantsInputKey == false);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,724 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Media;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewIntegerInputCell : DataGridViewTextBoxCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewIntegerInputEditingControl)); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof(string)); }
}
#endregion
#region ValueType
public override Type ValueType
{
get { return (typeof(int)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewIntegerInputEditingControl ctl =
(DataGridViewIntegerInputEditingControl)DataGridView.EditingControl;
DataGridViewIntegerInputColumn oc = OwningColumn as DataGridViewIntegerInputColumn;
if (oc != null)
{
IntegerInput di = oc.IntegerInput;
ctl.Value = GetValue(DataGridView[OwningColumn.Index, rowIndex].Value);
ctl.DisplayFormat = di.DisplayFormat;
ctl.Enabled = di.Enabled;
ctl.Increment = di.Increment;
ctl.InputHorizontalAlignment = GetHorizontalAlignment(dataGridViewCellStyle.Alignment);
ctl.LockUpdateChecked = di.LockUpdateChecked;
ctl.MaxValue = di.MaxValue;
ctl.MinValue = di.MinValue;
ctl.ShowCheckBox = di.ShowCheckBox;
ctl.ShowUpDown = di.ShowUpDown;
ctl.BackgroundStyle.ApplyStyle(di.BackgroundStyle);
ctl.BackgroundStyle.Class = di.BackgroundStyle.Class;
di.ButtonClear.CopyToItem(ctl.ButtonClear);
di.ButtonCustom.CopyToItem(ctl.ButtonCustom);
di.ButtonCustom2.CopyToItem(ctl.ButtonCustom2);
di.ButtonDropDown.CopyToItem(ctl.ButtonDropDown);
di.ButtonFreeText.CopyToItem(ctl.ButtonFreeText);
ctl.ButtonClearClick += ButtonClearClick;
ctl.ButtonCustomClick += ButtonCustomClick;
ctl.ButtonCustom2Click += ButtonCustom2Click;
ctl.ButtonDropDownClick += ButtonDropDownClick;
ctl.ButtonFreeTextClick += ButtonFreeTextClick;
ctl.ConvertFreeTextEntry += ConvertFreeTextEntry;
ctl.EditCancelled = false;
}
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewIntegerInputEditingControl di =
DataGridView.EditingControl as DataGridViewIntegerInputEditingControl;
if (di != null)
{
di.ButtonClearClick -= ButtonClearClick;
di.ButtonDropDownClick -= ButtonDropDownClick;
di.ButtonFreeTextClick -= ButtonFreeTextClick;
di.ButtonCustomClick -= ButtonCustomClick;
di.ButtonCustom2Click -= ButtonCustom2Click;
di.ConvertFreeTextEntry -= ConvertFreeTextEntry;
if (di.EditCancelled == true)
{
di.EditCancelled = false;
SystemSounds.Beep.Play();
}
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region ButtonClearClick
/// <summary>
/// ButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClearClick(object sender, CancelEventArgs e)
{
((DataGridViewIntegerInputColumn)OwningColumn).DoButtonClearClick(sender, e);
}
#endregion
#region ButtonCustomClick
/// <summary>
/// ButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustomClick(object sender, EventArgs e)
{
((DataGridViewIntegerInputColumn)OwningColumn).DoButtonCustomClick(sender, e);
}
#endregion
#region ButtonCustom2Click
/// <summary>
/// ButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustom2Click(object sender, EventArgs e)
{
((DataGridViewIntegerInputColumn)OwningColumn).DoButtonCustom2Click(sender, e);
}
#endregion
#region ButtonDropDownClick
/// <summary>
/// ButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonDropDownClick(object sender, CancelEventArgs e)
{
((DataGridViewIntegerInputColumn)OwningColumn).DoButtonDropDownClick(sender, e);
}
#endregion
#region ButtonFreeTextClick
/// <summary>
/// ButtonFreeTextClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonFreeTextClick(object sender, CancelEventArgs e)
{
((DataGridViewIntegerInputColumn)OwningColumn).DoButtonFreeTextClick(sender, e);
}
#endregion
#region ConvertFreeTextEntry
/// <summary>
/// ConvertFreeTextEntry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ConvertFreeTextEntry(object sender, FreeTextEntryConversionEventArgs e)
{
((DataGridViewIntegerInputColumn)OwningColumn).DoConvertFreeTextEntry(sender, e);
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
DataGridViewIntegerInputColumn oc = OwningColumn as DataGridViewIntegerInputColumn;
if (oc != null)
{
IntegerInput ip = oc.IntegerInput;
preferredSize.Height = ip.Height;
if (constraintSize.Width == 0)
{
preferredSize.Width += GetImageWidth(ip.ButtonClear);
preferredSize.Width += GetImageWidth(ip.ButtonCustom);
preferredSize.Width += GetImageWidth(ip.ButtonCustom2);
preferredSize.Width += GetImageWidth(ip.ButtonDropDown);
preferredSize.Width += GetImageWidth(ip.ButtonFreeText);
if (ip.ShowUpDown == true)
preferredSize.Width += 16;
if (ip.ShowCheckBox == true)
preferredSize.Width += 16;
}
}
return (preferredSize);
}
#endregion
#region GetFormattedValue
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
DataGridViewIntegerInputColumn oc = OwningColumn as DataGridViewIntegerInputColumn;
if (oc != null)
{
IntegerInput ip = oc.IntegerInput;
ip.Value = GetValue(value);
return (ip.Text);
}
return (base.GetFormattedValue(value, rowIndex,
ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
}
#endregion
#region GetImageWidth
private int GetImageWidth(InputButtonSettings ibs)
{
if (ibs.Visible == true)
return (ibs.Image != null ? ibs.Image.Width : 16);
return (0);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewIntegerInputColumn oc = (DataGridViewIntegerInputColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, value, cellStyle, paintParts);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts)
{
DataGridViewIntegerInputColumn oc = (DataGridViewIntegerInputColumn)OwningColumn;
IntegerInput di = oc.IntegerInput;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.BackgroundStyle.TextColor = cellStyle.ForeColor;
di.BackgroundStyle.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.InputHorizontalAlignment = GetHorizontalAlignment(cellStyle.Alignment);
di.Value = GetValue(value);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, r, g);
else
DrawText(di, r, g);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawControl(IntegerInput di, Rectangle r, Graphics g)
{
GraphicsState gs = g.Save();
try
{
g.TranslateTransform(r.X, r.Y);
di.Width = r.Width;
di.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
g.Restore(gs);
}
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawText(IntegerInput di, Rectangle r, Graphics g)
{
r.Inflate(-2, 0);
eTextFormat tf = eTextFormat.VerticalCenter;
switch (di.InputHorizontalAlignment)
{
case eHorizontalAlignment.Center:
tf |= eTextFormat.HorizontalCenter;
break;
case eHorizontalAlignment.Right:
tf |= eTextFormat.Right;
break;
}
TextDrawing.DrawString(g, di.Text, di.Font, di.ForeColor, r, tf);
}
#endregion
#endregion
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewIntegerInputColumn oc = (DataGridViewIntegerInputColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewIntegerInputColumn oc = (DataGridViewIntegerInputColumn)OwningColumn;
Size size = oc.IntegerInput.Size;
cellBounds.Location = new Point(1, 1);
cellBounds.Width = Math.Min(size.Width, cellBounds.Width);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = size.Height;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private int GetValue(object value)
{
if (value == Convert.DBNull ||
(value is string && String.IsNullOrEmpty((string) value) == true))
{
return (0);
}
return (Convert.ToInt32(value));
}
#endregion
#region GetHorizontalAlignment
/// <summary>
/// GetHorizontalAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private eHorizontalAlignment GetHorizontalAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (eHorizontalAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (eHorizontalAlignment.Right);
default:
return (eHorizontalAlignment.Left);
}
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,597 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "IntegerInput.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewIntegerInputColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a DateTimeInput Cell is painted
/// </summary>
[Description("Occurs right before an IntegerInput Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
/// <summary>
/// Occurs when Clear button is clicked and allows you
/// to cancel the default action performed by the button
/// </summary>
[Description("Occurs when Clear button is clicked and allows you to cancel the default action performed by the button.")]
public event EventHandler<CancelEventArgs> ButtonClearClick;
/// <summary>
/// Occurs when ButtonCustom control is clicked
/// </summary>
[Description("Occurs when ButtonCustom control is clicked.")]
public event EventHandler<EventArgs> ButtonCustomClick;
/// <summary>
/// Occurs when ButtonCustom2 control is clicked
/// </summary>
[Description("Occurs when ButtonCustom2 control is clicked.")]
public event EventHandler<EventArgs> ButtonCustom2Click;
/// <summary>
/// Occurs when Drop-Down button that shows calendar
/// is clicked and allows you to cancel showing of the popup
/// </summary>
[Description("Occurs when Drop-Down button that shows calendar is clicked and allows you to cancel showing of the popup.")]
public event EventHandler<CancelEventArgs> ButtonDropDownClick;
/// <summary>
/// Occurs when Free-Text button is clicked
/// and allows you to cancel its default action
/// </summary>
[Description("Occurs when Free-Text button is clicked and allows you to cancel its default action.")]
public event EventHandler<CancelEventArgs> ButtonFreeTextClick;
/// <summary>
/// Occurs if Free-Text entry value is not natively recognized by
/// the control and provides you with opportunity to convert that
/// value to the value the control expects
/// </summary>
[Description("Occurs if Free-Text entry value is not natively recognized by the control and provides you with opportunity to convert that value to the value the control expects.")]
public event EventHandler<FreeTextEntryConversionEventArgs> ConvertFreeTextEntry;
#endregion
#region Private variables
private IntegerInput _IngegerInput;
private Bitmap _CellBitmap;
private bool _DisplayControlForCurrentCellOnly = true;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewIntegerInputColumn()
{
CellTemplate = new DataGridViewIntegerInputCell();
_IngegerInput = new IntegerInput();
_IngegerInput.BackgroundStyle.Class = ElementStyleClassKeys.DataGridViewNumericBorderKey;
_IngegerInput.Visible = false;
}
#region Internal properties
#region IntegerInput
/// <summary>
/// IntegerInput
/// </summary>
internal IntegerInput IntegerInput
{
get { return (_IngegerInput); }
}
#endregion
#endregion
#region Public properties
#region BackgroundStyle
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Browsable(true), Category("Style")]
[Description("Gets or sets control background style.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return (_IngegerInput.BackgroundStyle); }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
_IngegerInput.ResetBackgroundStyle();
_IngegerInput.BackgroundStyle.Class = "TextBoxBorder";
_IngegerInput.BackgroundStyle.CornerType = eCornerType.Square;
}
#endregion
#region ButtonClear
/// <summary>
/// Gets the object that describes the settings for the button
/// that clears the content of the control when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that clears the content of the control when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonClear
{
get { return (_IngegerInput.ButtonClear); }
}
#endregion
#region ButtonCustom
/// <summary>
/// Gets the object that describes the settings for the custom button
/// that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom
{
get { return (_IngegerInput.ButtonCustom); }
}
#endregion
#region ButtonCustom2
/// <summary>
/// Gets the object that describes the settings for the custom button that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom2
{
get { return (_IngegerInput.ButtonCustom2); }
}
#endregion
#region ButtonDropDown
/// <summary>
/// Gets the object that describes the settings for the button
/// that shows drop-down when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that shows drop-down when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonDropDown
{
get { return (_IngegerInput.ButtonDropDown); }
}
#endregion
#region ButtonFreeText
/// <summary>
/// Gets the object that describes the settings for the button
/// that switches the control into the free-text entry mode when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that switches the control into the free-text entry mode when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonFreeText
{
get { return (_IngegerInput.ButtonFreeText); }
}
#endregion
#region DisplayFormat
/// <summary>
/// Gets or sets the Numeric String Format that is used to format
/// the numeric value entered for display purpose. Read more about
/// available formats in MSDN under "Standard Numeric Format Strings"
/// and "Custom Numeric Format Strings" topics.
/// <remarks>
/// The format specified here indicates the format for display purpose
/// only, not for the input purpose. For example to display the number
/// in system Currency format set the DisplayFormat to 'C'.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue("")]
[Description("Indicates Numeric String Format that is used to format the numeric value entered for display purpose.")]
public string DisplayFormat
{
get { return (_IngegerInput.DisplayFormat); }
set { _IngegerInput.DisplayFormat = value; }
}
#endregion
#region DisplayControlForCurrentCellOnly
/// <summary>
/// Gets or sets whether the control
/// will be displayed for the current cell only.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control will be displayed for the current cell only.")]
public bool DisplayControlForCurrentCellOnly
{
get { return (_DisplayControlForCurrentCellOnly); }
set
{
if (_DisplayControlForCurrentCellOnly != value)
{
_DisplayControlForCurrentCellOnly = value;
_IngegerInput.Invalidate();
}
}
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_IngegerInput.Enabled); }
set { _IngegerInput.Enabled = value; }
}
#endregion
#region Increment
/// <summary>
/// Gets or sets the value to increment or decrement the value of the
/// control when the up or down buttons are clicked.
/// </summary>
[Browsable(true), DefaultValue(1)]
[Description("Indicates value to increment or decrement the value of the control when the up or down buttons are clicked. ")]
public int Increment
{
get { return (_IngegerInput.Increment); }
set { _IngegerInput.Increment = value; }
}
#endregion
#region InputHorizontalAlignment
/// <summary>
/// Gets or sets the input field alignment inside the control
/// </summary>
[Browsable(true), DefaultValue(eHorizontalAlignment.Right), Category("Appearance")]
[Description("Indicates alignment of input fields inside of the control.")]
public eHorizontalAlignment InputHorizontalAlignment
{
get { return (_IngegerInput.InputHorizontalAlignment); }
set { _IngegerInput.InputHorizontalAlignment = value; }
}
#endregion
#region LockUpdateChecked
/// <summary>
/// Gets or sets whether check box shown using ShowCheckBox
/// property which locks/unlocks the control update is checked.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether check box shown using ShowCheckBox property which locks/unlocks the control update is checked.")]
public bool LockUpdateChecked
{
get { return (_IngegerInput.LockUpdateChecked); }
set { _IngegerInput.LockUpdateChecked = value; }
}
#endregion
#region MaxValue
/// <summary>
/// Gets or sets the maximum value that can be entered.
/// </summary>
[Browsable(true), DefaultValue(int.MaxValue)]
[Description("Indicates maximum value that can be entered.")]
public int MaxValue
{
get { return (_IngegerInput.MaxValue); }
set { _IngegerInput.MaxValue = value; }
}
#endregion
#region MinValue
/// <summary>
/// Gets or sets the minimum value that can be entered.
/// </summary>
[Browsable(true), DefaultValue(int.MinValue)]
[Description("Indicates minimum value that can be entered.")]
public int MinValue
{
get { return (_IngegerInput.MinValue); }
set { _IngegerInput.MinValue = value; }
}
#endregion
#region ShowCheckBox
/// <summary>
/// Gets or sets a value indicating whether a check box is
/// displayed to the left of the input value. Set to true if a check box
/// is displayed to the left of the input value; otherwise, false. The default is false.
/// <remarks>
/// When the ShowCheckBox property is set to true, a check box is displayed
/// to the left of the input in the control. When the check box is selected, the value
/// can be updated. When the check box is cleared, the value is unable to be changed.
/// You can handle the LockUpdateChanged event to be notified when this check box is checked
/// and unchecked. Use LockUpdateChecked property to get or sets whether check box is checked.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether a check box is displayed to the left of the input value which allows locking of the control.")]
public bool ShowCheckBox
{
get { return (_IngegerInput.ShowCheckBox); }
set { _IngegerInput.ShowCheckBox = value; }
}
#endregion
#region ShowUpDown
/// <summary>
/// Gets or sets a value indicating whether a spin button control
/// (up-down control) is used to adjust the current value. The default is false.
/// <remarks>
/// When the ShowUpDown property is set to true, a spin button control
/// is shown to adjust value of currently focused input item. The value can
/// be adjusted by using the up and down buttons to change the value.
/// </remarks>
/// </summary>
[Browsable(true), DefaultValue(false)]
public bool ShowUpDown
{
get { return (_IngegerInput.ShowUpDown); }
set { _IngegerInput.ShowUpDown = value; }
}
#endregion
#endregion
#region Event processing
#region DoButtonClearClick
/// <summary>
/// DoButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonClearClick(object sender, CancelEventArgs e)
{
if (ButtonClearClick != null)
ButtonClearClick(this, e);
}
#endregion
#region DoButtonCustomClick
/// <summary>
/// DoButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustomClick(object sender, EventArgs e)
{
if (ButtonCustomClick != null)
ButtonCustomClick(this, e);
}
#endregion
#region DoButtonCustom2Click
/// <summary>
/// DoButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustom2Click(object sender, EventArgs e)
{
if (ButtonCustom2Click != null)
ButtonCustom2Click(this, e);
}
#endregion
#region DoButtonDropDownClick
/// <summary>
/// DoButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonDropDownClick(object sender, CancelEventArgs e)
{
if (ButtonDropDownClick != null)
ButtonDropDownClick(this, e);
}
#endregion
#region DoButtonFreeTextClick
/// <summary>
/// DoButtonFreeTextClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonFreeTextClick(object sender, CancelEventArgs e)
{
if (ButtonFreeTextClick != null)
ButtonFreeTextClick(this, e);
}
#endregion
#region DoConvertFreeTextEntry
/// <summary>
/// DoConvertFreeTextEntry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoConvertFreeTextEntry(object sender, FreeTextEntryConversionEventArgs e)
{
if (ConvertFreeTextEntry != null)
ConvertFreeTextEntry(this, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewIntegerInputColumn dc = base.Clone() as DataGridViewIntegerInputColumn;
if (dc != null)
{
dc.DisplayFormat = DisplayFormat;
dc.Enabled = Enabled;
dc.Increment = Increment;
dc.InputHorizontalAlignment = InputHorizontalAlignment;
dc.LockUpdateChecked = LockUpdateChecked;
dc.MaxValue = MaxValue;
dc.MinValue = MinValue;
dc.ShowCheckBox = ShowCheckBox;
dc.ShowUpDown = ShowUpDown;
dc.DisplayControlForCurrentCellOnly = DisplayControlForCurrentCellOnly;
dc.BackgroundStyle.ApplyStyle(IntegerInput.BackgroundStyle);
dc.BackgroundStyle.Class = IntegerInput.BackgroundStyle.Class;
IntegerInput.ButtonClear.CopyToItem(dc.IntegerInput.ButtonClear);
IntegerInput.ButtonDropDown.CopyToItem(dc.IntegerInput.ButtonDropDown);
IntegerInput.ButtonFreeText.CopyToItem(dc.IntegerInput.ButtonFreeText);
IntegerInput.ButtonCustom.CopyToItem(dc.IntegerInput.ButtonCustom);
IntegerInput.ButtonCustom2.CopyToItem(dc.IntegerInput.ButtonCustom2);
}
return (dc);
}
#endregion
#region Dispose
protected override void Dispose(bool disposing)
{
if (disposing == true)
_IngegerInput.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
}
}

View File

@@ -0,0 +1,210 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewIntegerInputEditingControl : IntegerInput, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
private bool _EditCancelled;
#endregion
#region OnValueChanged
/// <summary>
/// Handles OnValueChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnValueChanged(EventArgs e)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
base.OnValueChanged(e);
}
#endregion
#region Internal properties
/// <summary>
/// Gets or sets the Edit state
/// </summary>
internal bool EditCancelled
{
get { return (_EditCancelled); }
set { _EditCancelled = value; }
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set { _DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get { return (this.Value.ToString()); }
set
{
string newValue = value as string;
if (newValue != null)
Value = int.Parse(newValue);
}
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (base.Cursor); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
ForeColor = dataGridViewCellStyle.ForeColor;
BackColor = dataGridViewCellStyle.BackColor;
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (EditingControlFormattedValue);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
if ((keyData & Keys.Escape) == Keys.Escape)
_EditCancelled = true;
return (dataGridViewWantsInputKey == false);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,711 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Media;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewIpAddressInputCell : DataGridViewTextBoxCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewIpAddressInputEditingControl)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewIpAddressInputEditingControl ctl =
(DataGridViewIpAddressInputEditingControl)DataGridView.EditingControl;
DataGridViewIpAddressInputColumn oc = (DataGridViewIpAddressInputColumn)OwningColumn;
IpAddressInput tb = oc.IpAddressInput;
ctl.Font = dataGridViewCellStyle.Font;
ctl.ForeColor = dataGridViewCellStyle.ForeColor;
ctl.BackColor = dataGridViewCellStyle.BackColor;
ctl.AllowEmptyState = tb.AllowEmptyState;
ctl.AutoOffFreeTextEntry = tb.AutoOffFreeTextEntry;
ctl.AutoOverwrite = tb.AutoOverwrite;
ctl.AutoResolveFreeTextEntries = tb.AutoResolveFreeTextEntries;
ctl.DropDownControl = tb.DropDownControl;
ctl.Enabled = tb.Enabled;
ctl.FocusHighlightColor = tb.FocusHighlightColor;
ctl.FocusHighlightEnabled = tb.FocusHighlightEnabled;
ctl.FreeTextEntryMode = tb.FreeTextEntryMode;
ctl.ImeMode = tb.ImeMode;
ctl.InputHorizontalAlignment = GetHorizontalAlignment(dataGridViewCellStyle.Alignment);
ctl.IsInputReadOnly = tb.IsInputReadOnly;
ctl.LockUpdateChecked = tb.LockUpdateChecked;
ctl.RightToLeft = tb.RightToLeft;
ctl.SelectNextInputCharacters = tb.SelectNextInputCharacters;
ctl.ShowCheckBox = tb.ShowCheckBox;
ctl.WatermarkColor = tb.WatermarkColor;
ctl.WatermarkEnabled = tb.WatermarkEnabled;
ctl.WatermarkFont = tb.WatermarkFont;
ctl.WatermarkText = tb.WatermarkText;
ctl.DropDownItems.Clear();
if (tb.DropDownItems.Count > 0)
{
for (int i = 0; i < tb.DropDownItems.Count; i++)
ctl.DropDownItems.Add(tb.DropDownItems[i]);
}
ctl.BackgroundStyle.ApplyStyle(tb.BackgroundStyle);
ctl.BackgroundStyle.Class = tb.BackgroundStyle.Class;
tb.ButtonClear.CopyToItem(ctl.ButtonClear);
tb.ButtonCustom.CopyToItem(ctl.ButtonCustom);
tb.ButtonCustom2.CopyToItem(ctl.ButtonCustom2);
tb.ButtonDropDown.CopyToItem(ctl.ButtonDropDown);
ctl.ButtonClearClick += ButtonClearClick;
ctl.ButtonCustomClick += ButtonCustomClick;
ctl.ButtonCustom2Click += ButtonCustom2Click;
ctl.ButtonDropDownClick += ButtonDropDownClick;
ctl.Value = GetValue(initialFormattedValue);
ctl.EditCancelled = false;
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewIpAddressInputEditingControl di =
DataGridView.EditingControl as DataGridViewIpAddressInputEditingControl;
if (di != null)
{
di.ButtonClearClick -= ButtonClearClick;
di.ButtonCustomClick -= ButtonCustomClick;
di.ButtonCustom2Click -= ButtonCustom2Click;
di.ButtonDropDownClick -= ButtonDropDownClick;
if (di.EditCancelled == true)
{
di.EditCancelled = false;
SystemSounds.Beep.Play();
}
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region ButtonClearClick
/// <summary>
/// ButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClearClick(object sender, CancelEventArgs e)
{
((DataGridViewIpAddressInputColumn)OwningColumn).DoButtonClearClick(sender, e);
}
#endregion
#region ButtonCustomClick
/// <summary>
/// ButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustomClick(object sender, EventArgs e)
{
((DataGridViewIpAddressInputColumn)OwningColumn).DoButtonCustomClick(sender, e);
}
#endregion
#region ButtonCustom2Click
/// <summary>
/// ButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustom2Click(object sender, EventArgs e)
{
((DataGridViewIpAddressInputColumn)OwningColumn).DoButtonCustom2Click(sender, e);
}
#endregion
#region ButtonDropDownClick
/// <summary>
/// ButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonDropDownClick(object sender, CancelEventArgs e)
{
((DataGridViewIpAddressInputColumn)OwningColumn).DoButtonDropDownClick(sender, e);
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (cellStyle != null && r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
DataGridViewIpAddressInputColumn oc = OwningColumn as DataGridViewIpAddressInputColumn;
if (oc != null)
{
IpAddressInput ip = oc.IpAddressInput;
preferredSize.Width += 6;
preferredSize.Height = ip.Height;
if (constraintSize.Width == 0)
{
preferredSize.Width += GetImageWidth(ip.ButtonClear);
preferredSize.Width += GetImageWidth(ip.ButtonCustom);
preferredSize.Width += GetImageWidth(ip.ButtonCustom2);
preferredSize.Width += GetImageWidth(ip.ButtonDropDown);
preferredSize.Width += GetImageWidth(ip.ButtonFreeText);
if (ip.ShowCheckBox == true)
preferredSize.Width += 16;
}
}
return (preferredSize);
}
#endregion
#region GetFormattedValue
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
DataGridViewIpAddressInputColumn oc = OwningColumn as DataGridViewIpAddressInputColumn;
if (oc != null)
{
IpAddressInput ip = oc.IpAddressInput;
ip.Value = GetValue(value);
return (ip.Text);
}
return (base.GetFormattedValue(value, rowIndex,
ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
}
#endregion
#region GetImageWidth
private int GetImageWidth(InputButtonSettings ibs)
{
if (ibs.Visible == true)
return (ibs.Image != null ? ibs.Image.Width : 16);
return (0);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewIpAddressInputColumn oc = (DataGridViewIpAddressInputColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, formattedValue, cellStyle, paintParts);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts)
{
DataGridViewIpAddressInputColumn oc = (DataGridViewIpAddressInputColumn)OwningColumn;
IpAddressInput di = oc.IpAddressInput;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
di.InputHorizontalAlignment = GetHorizontalAlignment(cellStyle.Alignment);
di.Value = GetValue(value);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, r, g);
else
DrawText(di, r, g);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawControl(IpAddressInput di, Rectangle r, Graphics g)
{
GraphicsState gs = g.Save();
try
{
g.TranslateTransform(r.X, r.Y);
di.Width = r.Width;
di.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
g.Restore(gs);
}
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawText(IpAddressInput di, Rectangle r, Graphics g)
{
r.Inflate(-2, 0);
eTextFormat tf = eTextFormat.VerticalCenter;
switch (di.InputHorizontalAlignment)
{
case eHorizontalAlignment.Center:
tf |= eTextFormat.HorizontalCenter;
break;
case eHorizontalAlignment.Right:
tf |= eTextFormat.Right;
break;
}
TextDrawing.DrawString(g, di.Text, di.Font, di.ForeColor, r, tf);
}
#endregion
#endregion
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewIpAddressInputColumn oc = (DataGridViewIpAddressInputColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewIpAddressInputColumn oc = (DataGridViewIpAddressInputColumn)OwningColumn;
oc.IpAddressInput.RecalcLayout();
Size size = oc.IpAddressInput.PreferredSize;
if (oc.IpAddressInput.ButtonClear.Visible == true)
{
if (oc.IpAddressInput.ButtonClear.Image != null)
size.Width += oc.IpAddressInput.ButtonClear.Image.Size.Width;
else
size.Width += 16;
}
if (oc.IpAddressInput.ButtonCustom.Visible == true)
{
if (oc.IpAddressInput.ButtonCustom.Image != null)
size.Width += oc.IpAddressInput.ButtonCustom.Image.Size.Width;
else
size.Width += 16;
}
if (oc.IpAddressInput.ButtonCustom2.Visible == true)
{
if (oc.IpAddressInput.ButtonCustom2.Image != null)
size.Width += oc.IpAddressInput.ButtonCustom2.Image.Size.Width;
else
size.Width += 16;
}
if (oc.IpAddressInput.ButtonDropDown.Visible == true)
{
if (oc.IpAddressInput.ButtonDropDown.Image != null)
size.Width += oc.IpAddressInput.ButtonDropDown.Image.Size.Width;
else
size.Width += 16;
}
cellBounds.Location = new Point(1, 1);
cellBounds.Width = Math.Min(size.Width, cellBounds.Width);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = size.Height;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private string GetValue(object value)
{
return (value != Convert.DBNull ? Convert.ToString(value) : "");
}
#endregion
#region GetHorizontalAlignment
/// <summary>
/// GetHorizontalAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private eHorizontalAlignment GetHorizontalAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (eHorizontalAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (eHorizontalAlignment.Right);
default:
return (eHorizontalAlignment.Left);
}
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,781 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "IpAddressInput.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewIpAddressInputColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a IpAddressInput Cell is painted
/// </summary>
[Description("Occurs right before a IpAddressInput Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
/// <summary>
/// Occurs when Clear button is clicked and allows you
/// to cancel the default action performed by the button
/// </summary>
[Description("Occurs when Clear button is clicked and allows you to cancel the default action performed by the button.")]
public event EventHandler<CancelEventArgs> ButtonClearClick;
/// <summary>
/// Occurs when ButtonCustom control is clicked
/// </summary>
[Description("Occurs when ButtonCustom control is clicked.")]
public event EventHandler<EventArgs> ButtonCustomClick;
/// <summary>
/// Occurs when ButtonCustom2 control is clicked
/// </summary>
[Description("Occurs when ButtonCustom2 control is clicked.")]
public event EventHandler<EventArgs> ButtonCustom2Click;
/// <summary>
/// Occurs when Drop-Down button that shows calendar
/// is clicked and allows you to cancel showing of the popup
/// </summary>
[Description("Occurs when Drop-Down button that shows calendar is clicked and allows you to cancel showing of the popup.")]
public event EventHandler<CancelEventArgs> ButtonDropDownClick;
#endregion
#region Private variables
private IpAddressInput _IpAddressInput;
private Bitmap _CellBitmap;
private bool _DisplayControlForCurrentCellOnly = true;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewIpAddressInputColumn()
{
CellTemplate = new DataGridViewIpAddressInputCell();
_IpAddressInput = new IpAddressInput();
_IpAddressInput.BackgroundStyle.Class = ElementStyleClassKeys.DataGridViewIpAddressBorderKey;
}
#region Internal properties
#region IpAddressInput
/// <summary>
/// Gets the underlying IpAddressInput control
/// </summary>
[Browsable(false)]
internal IpAddressInput IpAddressInput
{
get { return (_IpAddressInput); }
}
#endregion
#endregion
#region Public properties
#region AllowEmptyState
/// <summary>
/// Gets or sets whether empty null/nothing state of the control
/// is allowed. Default value is true which means that Text property
/// may return null if there is no input value.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether empty null/nothing state of the control is allowed.")]
public bool AllowEmptyState
{
get { return (_IpAddressInput.AllowEmptyState); }
set { _IpAddressInput.AllowEmptyState = value; }
}
#endregion
#region AutoOffFreeTextEntry
/// <summary>
/// Gets or sets whether free-text entry is automatically
/// turned off when control loses input focus. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Free-Text")]
[Description("Indicates whether free-text entry is automatically turned off when control loses input focus.")]
public bool AutoOffFreeTextEntry
{
get { return (_IpAddressInput.AutoOffFreeTextEntry); }
set { _IpAddressInput.AutoOffFreeTextEntry = value; }
}
#endregion
#region AutoOverwrite
/// <summary>
/// Gets or sets whether auto-overwrite functionality for input
/// is enabled. When in auto-overwrite mode input field will erase existing entry
/// and start new one if typing is continued after InputComplete method is called.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether auto-overwrite functionality for input is enabled.")]
public bool AutoOverwrite
{
get { return (_IpAddressInput.AutoOverwrite); }
set { _IpAddressInput.AutoOverwrite = value; }
}
#endregion
#region AutoResolveFreeTextEntries
/// <summary>
/// Gets or sets whether free text entries are attempted to be
/// auto-resolved to IP address as host/domain names. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Free-Text")]
[Description("Indicates whether free text entries are attempted to be auto-resolved to IP address as host/domain names.")]
public bool AutoResolveFreeTextEntries
{
get { return (_IpAddressInput.AutoResolveFreeTextEntries); }
set { _IpAddressInput.AutoResolveFreeTextEntries = value; }
}
#endregion
#region BackColor
/// <summary>
/// Gets or sets the Background color.
/// </summary>
[Browsable(false)]
public Color BackColor
{
get { return (_IpAddressInput.BackColor); }
set { _IpAddressInput.BackColor = value; }
}
#endregion
#region BackgroundStyle
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Browsable(true), Category("Style")]
[Description("Gets or sets control background style.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return (_IpAddressInput.BackgroundStyle); }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
_IpAddressInput.ResetBackgroundStyle();
_IpAddressInput.BackgroundStyle.Class = "TextBoxBorder";
_IpAddressInput.BackgroundStyle.CornerType = eCornerType.Square;
}
#endregion
#region ButtonClear
/// <summary>
/// Gets the object that describes the settings for the button
/// that clears the content of the control when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that clears the content of the control when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonClear
{
get { return (_IpAddressInput.ButtonClear); }
}
#endregion
#region ButtonCustom
/// <summary>
/// Gets the object that describes the settings for the custom button
/// that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom
{
get { return (_IpAddressInput.ButtonCustom); }
}
#endregion
#region ButtonCustom2
/// <summary>
/// Gets the object that describes the settings for the custom button that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom2
{
get { return (_IpAddressInput.ButtonCustom2); }
}
#endregion
#region ButtonDropDown
/// <summary>
/// Gets the object that describes the settings for the button
/// that shows drop-down when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that shows drop-down when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonDropDown
{
get { return (_IpAddressInput.ButtonDropDown); }
}
#endregion
#region DisplayControlForCurrentCellOnly
/// <summary>
/// Gets or sets whether the control
/// will be displayed for the current cell only.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control will be displayed for the current cell only.")]
public bool DisplayControlForCurrentCellOnly
{
get { return (_DisplayControlForCurrentCellOnly); }
set
{
if (_DisplayControlForCurrentCellOnly != value)
{
_DisplayControlForCurrentCellOnly = value;
_IpAddressInput.Invalidate();
}
}
}
#endregion
#region DropDownControl
/// <summary>
/// Gets or sets the reference of the control that will be
/// displayed on popup that is shown when the drop-down button is clicked.
/// </summary>
[DefaultValue(null)]
[Description("Indicates reference of the control that will be displayed on popup that is shown when the drop-down button is clicked.")]
public Control DropDownControl
{
get { return (_IpAddressInput.DropDownControl); }
set { _IpAddressInput.DropDownControl = value; }
}
#endregion
#region DropDownItems
/// <summary>
/// Returns the collection of DropDownItems.
/// </summary>
[Browsable(false), DevCoBrowsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SubItemsCollection DropDownItems
{
get { return (_IpAddressInput.DropDownItems); }
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_IpAddressInput.Enabled); }
set { _IpAddressInput.Enabled = value; }
}
#endregion
#region FocusHighlightColor
/// <summary>
/// Gets or sets the color used as background color to highlight
/// the text box when it has input focus and FocusHighlight is enabled.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates color used as background color to highlight the text box when it has input focus and FocusHighlight is enabled.")]
public Color FocusHighlightColor
{
get { return (_IpAddressInput.FocusHighlightColor); }
set { _IpAddressInput.FocusHighlightColor = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeFocusHighlightColor()
{
return (_IpAddressInput.ShouldSerializeFocusHighlightColor());
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetFocusHighlightColor()
{
_IpAddressInput.ResetFocusHighlightColor();
}
#endregion
#region FocusHighlightEnabled
/// <summary>
/// Gets or sets whether FocusHighlightColor is used as
/// background color to highlight the text box when it has
/// input focus. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Appearance")]
[Description("Indicates whether FocusHighlightColor is used as background color to highlight the text box when it has input focus.")]
public bool FocusHighlightEnabled
{
get { return (_IpAddressInput.FocusHighlightEnabled); }
set { _IpAddressInput.FocusHighlightEnabled = value; }
}
#endregion
#region ForeColor
/// <summary>
/// Gets or sets the foreground color.
/// </summary>
[Browsable(false)]
public Color ForeColor
{
get { return (_IpAddressInput.ForeColor); }
set { _IpAddressInput.ForeColor = value; }
}
#endregion
#region FreeTextEntryMode
/// <summary>
/// Gets or sets whether control input is in
/// free-text input mode. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Free-Text")]
[Description("Indicates whether control input is in free-text input mode.")]
public bool FreeTextEntryMode
{
get { return (_IpAddressInput.FreeTextEntryMode); }
set { _IpAddressInput.FreeTextEntryMode = value; }
}
#endregion
#region ImeMode
/// <summary>
/// Gets or sets the Input Method Editor (IME) mode of the control.
/// </summary>
[Browsable(true), DefaultValue(ImeMode.Inherit)]
[Description("Indicates the Input Method Editor (IME) mode of the control.")]
public ImeMode ImeMode
{
get { return (_IpAddressInput.ImeMode); }
set { _IpAddressInput.ImeMode = value; }
}
#endregion
#region IsInputReadOnly
/// <summary>
/// Gets or sets whether input part of the control is read-only. When
/// set to true the input part of the control becomes read-only and does
/// not allow the typing. However, drop-down part if visible still allows
/// user to possibly change the value of the control through the method you
/// can provide on drop-down. Use this property to allow change of the value
/// through drop-down button only.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether input part of the control is read-only.")]
public bool IsInputReadOnly
{
get { return (_IpAddressInput.IsInputReadOnly); }
set { _IpAddressInput.IsInputReadOnly = value; }
}
#endregion
#region LockUpdateChecked
/// <summary>
/// Gets or sets whether check box shown using ShowCheckBox
/// property which locks/unlocks the control update is checked.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether check box shown using ShowCheckBox property which locks/unlocks the control update is checked.")]
public bool LockUpdateChecked
{
get { return (_IpAddressInput.LockUpdateChecked); }
set { _IpAddressInput.LockUpdateChecked = value; }
}
#endregion
#region RightToLeft
/// <summary>
/// Gets or sets a value indicating whether control's
/// elements are aligned to support locales using right-to-left fonts.
/// </summary>
[Browsable(true), DefaultValue(RightToLeft.Inherit)]
[Description("Indicates the control's elements are aligned to support locales using right-to-left fonts.")]
public RightToLeft RightToLeft
{
get { return (_IpAddressInput.RightToLeft); }
set { _IpAddressInput.RightToLeft = value; }
}
#endregion
#region SelectNextInputCharacters
/// <summary>
/// List of characters that when pressed would select next input field. For example if you are
/// allowing time input you could set this property to : so when user presses the : character,
/// the input is forwarded to the next input field.
/// </summary>
[DefaultValue("."), Category("Behavior")]
[Description("List of characters that when pressed would select next input field.")]
public string SelectNextInputCharacters
{
get { return (_IpAddressInput.SelectNextInputCharacters); }
set { _IpAddressInput.SelectNextInputCharacters = value; }
}
#endregion
#region ShowCheckBox
/// <summary>
/// Gets or sets a value indicating whether a check box is displayed to
/// the left of the input value. Set to true if a check box is displayed
/// to the left of the input value; otherwise, false. The default is false.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether a check box is displayed to the left of the input value which allows locking of the control.")]
public bool ShowCheckBox
{
get { return (_IpAddressInput.ShowCheckBox); }
set { _IpAddressInput.ShowCheckBox = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text as it is currently displayed to the user.
/// </summary>
[Browsable(false)]
public string Text
{
get { return (_IpAddressInput.Text); }
set { _IpAddressInput.Text = value; }
}
#endregion
#region WatermarkColor
/// <summary>
/// Gets or sets the watermark text color.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates watermark text color.")]
public Color WatermarkColor
{
get { return (_IpAddressInput.WatermarkColor); }
set { _IpAddressInput.WatermarkColor = value; }
}
/// <summary>
/// Indicates whether property should be serialized by Windows Forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeWatermarkColor()
{
return (_IpAddressInput.ShouldSerializeWatermarkColor());
}
/// <summary>
/// Resets the property to default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetWatermarkColor()
{
_IpAddressInput.ResetWatermarkColor();
}
#endregion
#region WatermarkEnabled
/// <summary>
/// Gets or sets whether watermark text is
/// displayed when control is empty. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether watermark text is displayed when control is empty.")]
public virtual bool WatermarkEnabled
{
get { return (_IpAddressInput.WatermarkEnabled); }
set { _IpAddressInput.WatermarkEnabled = value; }
}
#endregion
#region WatermarkFont
/// <summary>
/// Gets or sets the watermark font.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates watermark font.")]
public Font WatermarkFont
{
get { return (_IpAddressInput.WatermarkFont); }
set { _IpAddressInput.WatermarkFont = value; }
}
#endregion
#region WatermarkText
/// <summary>
/// Gets or sets the watermark (tip) text displayed inside of
/// the control when Text is not set and control does not have
/// input focus. This property supports text-markup.
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates watermark text displayed inside of the control when Text is not set and control does not have input focus.")]
[Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
public string WatermarkText
{
get { return (_IpAddressInput.WatermarkText); }
set { _IpAddressInput.WatermarkText = value; }
}
#endregion
#endregion
#region Event processing
#region DoButtonClearClick
/// <summary>
/// DoButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonClearClick(object sender, CancelEventArgs e)
{
if (ButtonClearClick != null)
ButtonClearClick(this, e);
}
#endregion
#region DoButtonCustomClick
/// <summary>
/// DoButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustomClick(object sender, EventArgs e)
{
if (ButtonCustomClick != null)
ButtonCustomClick(this, e);
}
#endregion
#region DoButtonCustom2Click
/// <summary>
/// DoButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustom2Click(object sender, EventArgs e)
{
if (ButtonCustom2Click != null)
ButtonCustom2Click(this, e);
}
#endregion
#region DoButtonDropDownClick
/// <summary>
/// DoButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonDropDownClick(object sender, CancelEventArgs e)
{
if (ButtonDropDownClick != null)
ButtonDropDownClick(this, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewIpAddressInputColumn dc = base.Clone() as DataGridViewIpAddressInputColumn;
if (dc != null)
{
dc.AllowEmptyState = AllowEmptyState;
dc.AutoOffFreeTextEntry = AutoOffFreeTextEntry;
dc.AutoOverwrite = AutoOverwrite;
dc.AutoResolveFreeTextEntries = AutoResolveFreeTextEntries;
dc.DropDownControl = DropDownControl;
dc.Enabled = Enabled;
dc.FocusHighlightColor = FocusHighlightColor;
dc.FocusHighlightEnabled = FocusHighlightEnabled;
dc.FreeTextEntryMode = FreeTextEntryMode;
dc.ImeMode = ImeMode;
dc.IsInputReadOnly = IsInputReadOnly;
dc.LockUpdateChecked = LockUpdateChecked;
dc.RightToLeft = RightToLeft;
dc.SelectNextInputCharacters = SelectNextInputCharacters;
dc.ShowCheckBox = ShowCheckBox;
dc.WatermarkColor = WatermarkColor;
dc.WatermarkEnabled = WatermarkEnabled;
dc.WatermarkFont = WatermarkFont;
dc.WatermarkText = WatermarkText;
dc.DisplayControlForCurrentCellOnly = DisplayControlForCurrentCellOnly;
dc.BackgroundStyle.ApplyStyle(IpAddressInput.BackgroundStyle);
dc.BackgroundStyle.Class = IpAddressInput.BackgroundStyle.Class;
IpAddressInput.ButtonClear.CopyToItem(dc.IpAddressInput.ButtonClear);
IpAddressInput.ButtonDropDown.CopyToItem(dc.IpAddressInput.ButtonDropDown);
IpAddressInput.ButtonCustom.CopyToItem(dc.IpAddressInput.ButtonCustom);
IpAddressInput.ButtonCustom2.CopyToItem(dc.IpAddressInput.ButtonCustom2);
}
return (dc);
}
#endregion
#region Dispose
protected override void Dispose(bool disposing)
{
if (disposing == true)
_IpAddressInput.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
}
}

View File

@@ -0,0 +1,199 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewIpAddressInputEditingControl : IpAddressInput, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
private bool _EditCancelled;
#endregion
#region Internal properties
/// <summary>
/// Gets or sets the Edit state
/// </summary>
internal bool EditCancelled
{
get { return (_EditCancelled); }
set { _EditCancelled = value; }
}
#endregion
#region OnTextChanged
/// <summary>
/// Handles OnTextChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(EventArgs e)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
base.OnTextChanged(e);
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set { _DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get { return (Value ?? ""); }
set { Value = (string)value; }
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (base.Cursor); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (EditingControlFormattedValue);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
if ((keyData & Keys.Escape) == Keys.Escape)
_EditCancelled = true;
return (dataGridViewWantsInputKey == false);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,666 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewLabelXCell : DataGridViewButtonCell
{
#region Private variables
private DataGridViewCellStyle _CellStyle;
#endregion
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (null); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof(string)); }
}
#endregion
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle, int rowIndex)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetContentBounds(rowIndex);
if (cellStyle != null)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.TopCenter:
editingControlBounds.X += (editingControlBounds.Width - r.Width) / 2;
break;
case DataGridViewContentAlignment.TopRight:
editingControlBounds.X = (editingControlBounds.Right - r.Width);
break;
case DataGridViewContentAlignment.MiddleLeft:
editingControlBounds.Y += (editingControlBounds.Height - r.Height)/2;
break;
case DataGridViewContentAlignment.MiddleCenter:
editingControlBounds.X += (editingControlBounds.Width - r.Width)/2;
editingControlBounds.Y += (editingControlBounds.Height - r.Height)/2;
break;
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.X = (editingControlBounds.Right - r.Width);
editingControlBounds.Y += (editingControlBounds.Height - r.Height)/2;
break;
case DataGridViewContentAlignment.BottomLeft:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
case DataGridViewContentAlignment.BottomCenter:
editingControlBounds.X += (editingControlBounds.Width - r.Width)/2;
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.X = (editingControlBounds.Right - r.Width);
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
if (editingControlBounds.Y < 1)
editingControlBounds.Y = 1;
editingControlBounds.Width = Math.Max(1, r.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
Size size = Size.Empty;
if (DataGridView == null)
return new Size(-1, -1);
DataGridViewLabelXColumn oc = OwningColumn as DataGridViewLabelXColumn;
if (oc != null)
{
LabelX lx = oc.LabelX;
if (oc.LabelX.IsHandleCreated == false)
{
if (oc.LabelX.Parent == null)
{
Form form = oc.DataGridView.FindForm();
if (form != null)
oc.LabelX.Parent = form;
}
oc.LabelX.Visible = true;
oc.LabelX.Visible = false;
}
FreeDimension fd = GetDFromConstraint(constraintSize);
if (fd != FreeDimension.Width)
constraintSize.Width -= 2;
lx.Font = cellStyle.Font;
lx.WordWrap = GetWordWrap(oc, cellStyle);
lx.TextAlignment = GetTextAlignment(cellStyle.Alignment);
lx.MaximumSize = Size.Empty;
lx.Image = oc.Image;
string s = lx.Text = @" ";
if (rowIndex < DataGridView.RowCount)
s = GetValue(DataGridView.Rows[rowIndex].Cells[ColumnIndex].Value);
if (string.IsNullOrEmpty(s) == true)
s = " ";
lx.Text = s;
size = lx.GetPreferredSize(constraintSize);
Rectangle stdBorderWidths = BorderWidths(new DataGridViewAdvancedBorderStyle());
int hpad = (stdBorderWidths.Left + stdBorderWidths.Width) + cellStyle.Padding.Horizontal;
int vpad = (stdBorderWidths.Top + stdBorderWidths.Height) + cellStyle.Padding.Vertical;
switch (fd)
{
case FreeDimension.Height:
size.Width = 0;
break;
case FreeDimension.Width:
size.Height = 0;
break;
}
if (fd != FreeDimension.Height)
size.Width += (hpad + 4);
if (fd != FreeDimension.Width)
size.Height += (vpad + 2);
}
return size;
}
#region GetDFromConstraint
private enum FreeDimension
{
Both,
Height,
Width
}
private FreeDimension GetDFromConstraint(Size constraintSize)
{
if (constraintSize.Width == 0)
{
if (constraintSize.Height == 0)
return (FreeDimension.Both);
return (FreeDimension.Width);
}
return (FreeDimension.Height);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewLabelXColumn oc = (DataGridViewLabelXColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintLabelBackground(g, cellStyle, rBk);
PaintLabelContent(cellBounds, rowIndex, formattedValue, cellStyle, paintParts, g);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintLabelBackground
/// <summary>
/// Paints the Label background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintLabelBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintLabelContent
/// <summary>
/// Paints the Label background and content
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="g"></param>
private void PaintLabelContent(Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Graphics g)
{
DataGridViewLabelXColumn oc = (DataGridViewLabelXColumn) OwningColumn;
LabelX lx = oc.LabelX;
_CellStyle = cellStyle;
string s = GetValue(value);
oc.InCallBack = true;
bool wordWrap = lx.WordWrap;
StringAlignment textAlignment = lx.TextAlignment;
GraphicsState gs = g.Save();
try
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
lx.Font = cellStyle.Font;
lx.ForeColor = cellStyle.ForeColor;
lx.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
lx.WordWrap = GetWordWrap(oc, cellStyle);
lx.TextAlignment = GetTextAlignment(cellStyle.Alignment);
Rectangle r = cellBounds;
if (rowIndex < DataGridView.RowCount)
{
lx.Text = s;
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
r = GetAdjustedEditingControlBounds(cellBounds, cellStyle, rowIndex);
}
else
{
lx.Text = " ";
}
lx.CallBasePaintBackground = false;
g.TranslateTransform(r.X, r.Y);
lx.Bounds = r;
lx.RecalcLayout();
lx.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
lx.WordWrap = wordWrap;
lx.TextAlignment = textAlignment;
oc.InCallBack = false;
g.Restore(gs);
}
}
#region GetWordWrap
private bool GetWordWrap(DataGridViewLabelXColumn oc, DataGridViewCellStyle cellStyle)
{
if (oc.WordWrap == true)
return (true);
switch (cellStyle.WrapMode)
{
case DataGridViewTriState.True:
return (true);
case DataGridViewTriState.False:
return (false);
}
return (DataGridView.DefaultCellStyle.WrapMode == DataGridViewTriState.True);
}
#endregion
#endregion
#endregion
#region Mouse processing
#region OnMouseEnter
/// <summary>
/// OnMouseEnter
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseEnter(int rowIndex)
{
base.OnMouseEnter(rowIndex);
DataGridViewLabelXColumn oc = (DataGridViewLabelXColumn)OwningColumn;
LabelX bx = oc.LabelX;
bx.LabelItem.InternalMouseEnter();
}
#endregion
#region OnMouseLeave
/// <summary>
/// Processes MouseLeave events
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseLeave(int rowIndex)
{
base.OnMouseLeave(rowIndex);
DataGridViewLabelXColumn oc = (DataGridViewLabelXColumn)OwningColumn;
LabelX bx = oc.LabelX;
bx.LabelItem.InternalMouseLeave();
}
#endregion
#region OnMouseMove
/// <summary>
/// Processes MouseMove events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
{
base.OnMouseMove(e);
DataGridViewLabelXColumn oc = OwningColumn as DataGridViewLabelXColumn;
if (oc != null)
{
if ((uint)e.RowIndex < DataGridView.Rows.Count)
{
Point pt = CellAlignPoint(e);
oc.LabelX.LabelItem.InternalMouseMove(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
}
}
}
#endregion
#region OnMouseDown
/// <summary>
/// Processes MouseDown events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
{
base.OnMouseDown(e);
DataGridViewLabelXColumn oc = OwningColumn as DataGridViewLabelXColumn;
if (oc != null)
{
Point pt = CellAlignPoint(e);
oc.LabelX.LabelItem.InternalMouseDown(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
RefreshCell(e.ColumnIndex, e.RowIndex);
}
}
#endregion
#region OnMouseUp
/// <summary>
/// Processes MouseUp events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
{
base.OnMouseUp(e);
DataGridViewLabelXColumn oc = OwningColumn as DataGridViewLabelXColumn;
if (oc != null)
{
Point pt = CellAlignPoint(e);
oc.LabelX.LabelItem.InternalMouseUp(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
RefreshCell(e.ColumnIndex, e.RowIndex);
}
}
#endregion
#region CellAlignPoint
/// <summary>
/// CellAlignPoint
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
private Point CellAlignPoint(DataGridViewCellMouseEventArgs e)
{
Rectangle bounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
bounds.Location = new Point(0, 0);
Rectangle r = GetAdjustedEditingControlBounds(bounds, _CellStyle, e.RowIndex);
return (new Point(e.X - r.X, e.Y - r.Y));
}
#endregion
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewLabelXColumn oc = (DataGridViewLabelXColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private string GetValue(object value)
{
return (value != Convert.DBNull ? Convert.ToString(value) : "");
}
#endregion
#region GetTextAlignment
/// <summary>
/// GetHorizontalAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private StringAlignment GetTextAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (StringAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (StringAlignment.Far);
default:
return (StringAlignment.Near);
}
}
#endregion
#region RefreshCell
/// <summary>
/// Initiates the refresh of the cell label
/// </summary>
/// <param name="columnIndex"></param>
/// <param name="rowIndex"></param>
internal void RefreshCell(int columnIndex, int rowIndex)
{
DataGridView.InvalidateCell(columnIndex, rowIndex);
}
#endregion
}
}

View File

@@ -0,0 +1,515 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewLabelXColumn), "Controls.LabelX.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewLabelXColumn : DataGridViewButtonColumn, IDataGridViewColumn
{
#region Events
[Description("Occurs right before a LabelX Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
[Description("Occurs when a LabelX Cell is Clicked.")]
public event EventHandler<EventArgs> Click;
#endregion
#region Private variables
private LabelX _LabelX;
private Bitmap _CellBitmap;
private bool _InCellCallBack;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewLabelXColumn()
{
CellTemplate = new DataGridViewLabelXCell();
_LabelX = new LabelX();
_LabelX.CreateControl();
_LabelX.Visible = false;
HookEvents(true);
}
#region Hidden properties
/// <summary>
/// Button FlatStyle
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new FlatStyle FlatStyle
{
get { return base.FlatStyle; }
set { base.FlatStyle = value; }
}
/// <summary>
/// Button UseColumnTextForButtonValue
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new bool UseColumnTextForButtonValue
{
get { return base.UseColumnTextForButtonValue; }
set { base.UseColumnTextForButtonValue = value; }
}
#endregion
#region Internal properties
#region InCallBack
/// <summary>
/// InCallBack
/// </summary>
internal bool InCallBack
{
get { return (_InCellCallBack); }
set { _InCellCallBack = value; }
}
#endregion
#region LabelX
/// <summary>
/// Gets the Control LabelX
/// </summary>
internal LabelX LabelX
{
get { return (_LabelX); }
}
#endregion
#endregion
#region Public properties
#region EnableMarkup
/// <summary>
/// Gets or sets whether text-markup support is enabled for items Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the item instead of it being parsed as text-markup.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether text-markup support is enabled for the item's Text property.")]
public bool EnableMarkup
{
get { return (_LabelX.EnableMarkup); }
set { _LabelX.EnableMarkup = value; }
}
#endregion
#region FocusCuesEnabled
/// <summary>
/// Gets or sets whether control displays focus cues when focused.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Behavior")]
[Description("Indicates whether control displays focus cues when focused.")]
public bool FocusCuesEnabled
{
get { return (_LabelX.FocusCuesEnabled); }
set { _LabelX.FocusCuesEnabled = value; }
}
#endregion
#region BorderSide
/// <summary>
/// Gets or sets the border sides that are displayed.
/// Default value specifies border on all 4 sides.
/// </summary>
[Browsable(false), Category("Appearance"), DefaultValue(LabelItem.DEFAULT_BORDERSIDE)]
[Description("Specifies border sides that are displayed.")]
public eBorderSide BorderSide
{
get { return (_LabelX.BorderSide); }
set { _LabelX.BorderSide = value; }
}
#endregion
#region BorderType
/// <summary>
/// Gets or sets the type of the border drawn around the label.
/// </summary>
[Browsable(false), Category("Appearance"), DefaultValue(eBorderType.None)]
[Description("Indicates the type of the border drawn around the label.")]
public eBorderType BorderType
{
get { return (_LabelX.BorderType); }
set { _LabelX.BorderType = value; }
}
#endregion
#region Image
/// <summary>
/// Specifies label image.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("The image that will be displayed on the face of the item.")]
public Image Image
{
get { return (_LabelX.Image); }
set { _LabelX.Image = value; }
}
#endregion
#region ImagePosition
/// <summary>
/// Gets/Sets the image position inside the label.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(eImagePosition.Left)]
[Description("The alignment of the image in relation to text displayed by this item.")]
public eImagePosition ImagePosition
{
get { return (_LabelX.ImagePosition); }
set { _LabelX.ImagePosition = value; }
}
#endregion
#region PaddingBottom
/// <summary>
/// Gets or sets the bottom padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout")]
[Description("Indicates bottom padding in pixels.")]
public int PaddingBottom
{
get { return (_LabelX.PaddingBottom); }
set { _LabelX.PaddingBottom = value; }
}
#endregion
#region PaddingLeft
/// <summary>
/// Gets or sets the left padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout")]
[Description("Indicates left padding in pixels.")]
public int PaddingLeft
{
get { return (_LabelX.PaddingLeft); }
set { _LabelX.PaddingLeft = value; }
}
#endregion
#region PaddingTop
/// <summary>
/// Gets or sets the top padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout")]
[Description("Indicates top padding in pixels.")]
public int PaddingTop
{
get { return (_LabelX.PaddingTop); }
set { _LabelX.PaddingTop = value; }
}
#endregion
#region PaddingRight
/// <summary>
/// Gets or sets the right padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout")]
[Description("Indicates right padding in pixels.")]
public int PaddingRight
{
get { return (_LabelX.PaddingRight); }
set { _LabelX.PaddingRight = value; }
}
#endregion
#region SingleLineColor
/// <summary>
/// Gets or sets the border line color when border is single line.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates border line color when border is single line.")]
public Color SingleLineColor
{
get { return (_LabelX.SingleLineColor); }
set { _LabelX.SingleLineColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSingleLineColor()
{
return (_LabelX.ShouldSerializeSingleLineColor());
}
/// <summary>
/// Resets the SingleLineColor property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSingleLineColor()
{
_LabelX.ResetSingleLineColor();
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text associated with this item.
/// </summary>
[Browsable(true), Category("Appearance")]
[Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
[Description("The text contained in the item.")]
public new string Text
{
get
{
return (_InCellCallBack == true ?
_LabelX.Text : base.Text);
}
set
{
if (_InCellCallBack == true)
_LabelX.Text = value;
else
base.Text = value;
}
}
#endregion
#region TextAlignment
/// <summary>
/// Gets or sets the horizontal text alignment.
/// </summary>
[Browsable(true), DefaultValue(StringAlignment.Near), DevCoBrowsable(true), Category("Layout")]
[Description("Indicates the horizontal text alignment.")]
public StringAlignment TextAlignment
{
get { return (_LabelX.TextAlignment); }
set { _LabelX.TextAlignment = value; }
}
#endregion
#region TextLineAlignment
/// <summary>
/// Gets or sets the vertical text alignment.
/// </summary>
[Browsable(true), DefaultValue(StringAlignment.Center), DevCoBrowsable(true), Category("Layout")]
[Description("Indicates vertical text line alignment.")]
public StringAlignment TextLineAlignment
{
get { return (_LabelX.TextLineAlignment); }
set { _LabelX.TextLineAlignment = value; }
}
#endregion
#region UseMnemonic
/// <summary>
/// Gets or sets a value indicating whether the control interprets an
/// ampersand character (&) in the control's Text property to be an
/// access key prefix character.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control interprets an ampersand character (&) in the control's Text property to be an access key prefix character.")]
public bool UseMnemonic
{
get { return (_LabelX.UseMnemonic); }
set { _LabelX.UseMnemonic = value; }
}
#endregion
#region WordWrap
/// <summary>
/// Gets or sets a value that determines whether text is displayed in multiple lines or one long line.
/// </summary>
[Browsable(true), Category("Style"), DefaultValue(false)]
[Description("Indicates whether text is displayed in multiple lines or one long line.")]
public bool WordWrap
{
get { return (_LabelX.WordWrap); }
set { _LabelX.WordWrap = value; }
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// Hooks or unhooks our system events
/// </summary>
/// <param name="hook"></param>
private void HookEvents(bool hook)
{
if (hook == true)
{
_LabelX.LabelItem.Click += LabelItemClick;
}
else
{
_LabelX.LabelItem.Click -= LabelItemClick;
}
}
#endregion
#region Event processing
#region LabelItem_Click
/// <summary>
/// LabelItem_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void LabelItemClick(object sender, EventArgs e)
{
if (Click != null)
Click(sender, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the LabelX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewLabelXColumn bc = base.Clone() as DataGridViewLabelXColumn;
if (bc != null)
{
_LabelX.LabelItem.InternalCopyToItem(bc.LabelX.LabelItem);
bc.FocusCuesEnabled = FocusCuesEnabled;
bc.Text = Text;
bc.UseMnemonic = UseMnemonic;
}
return (bc);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the ButtonX control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
HookEvents(false);
if (disposing == true)
_LabelX.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
}
}

View File

@@ -0,0 +1,790 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewMaskedTextBoxAdvCell : DataGridViewTextBoxCell
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewMaskedTextBoxAdvEditingControl)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewMaskedTextBoxAdvEditingControl ctl =
(DataGridViewMaskedTextBoxAdvEditingControl) DataGridView.EditingControl;
DataGridViewMaskedTextBoxAdvColumn oc = OwningColumn as DataGridViewMaskedTextBoxAdvColumn;
if (oc != null)
{
MaskedTextBoxAdv tb = oc.MaskedTextBoxAdv;
ctl.AllowPromptAsInput = tb.AllowPromptAsInput;
ctl.AsciiOnly = tb.AsciiOnly;
ctl.BeepOnError = false;
ctl.Culture = tb.Culture;
ctl.CutCopyMaskFormat = tb.CutCopyMaskFormat;
ctl.DropDownControl = tb.DropDownControl;
ctl.Enabled = tb.Enabled;
ctl.FocusHighlightColor = tb.FocusHighlightColor;
ctl.FocusHighlightEnabled = tb.FocusHighlightEnabled;
ctl.HidePromptOnLeave = tb.HidePromptOnLeave;
ctl.ImeMode = tb.ImeMode;
ctl.InsertKeyMode = tb.InsertKeyMode;
ctl.Mask = tb.Mask;
ctl.PasswordChar = tb.PasswordChar;
ctl.PromptChar = tb.PromptChar;
ctl.RejectInputOnFirstFailure = tb.RejectInputOnFirstFailure;
ctl.ResetOnPrompt = tb.ResetOnPrompt;
ctl.ResetOnSpace = tb.ResetOnSpace;
ctl.RightToLeft = tb.RightToLeft;
ctl.SkipLiterals = tb.SkipLiterals;
ctl.TextAlign = GetTextAlignment(dataGridViewCellStyle.Alignment);
ctl.TextMaskFormat = tb.TextMaskFormat;
ctl.UseSystemPasswordChar = tb.UseSystemPasswordChar;
ctl.ValidatingType = tb.ValidatingType;
ctl.WatermarkBehavior = tb.WatermarkBehavior;
ctl.WatermarkColor = tb.WatermarkColor;
ctl.WatermarkEnabled = tb.WatermarkEnabled;
ctl.WatermarkFont = tb.WatermarkFont;
ctl.WatermarkText = tb.WatermarkText;
// The underlying MaskedTextBox's MultiLine property
// is "not fully supported" - but we'll set it anyway.
ctl.MaskedTextBox.Multiline = (dataGridViewCellStyle.WrapMode == DataGridViewTriState.True);
ctl.BackgroundStyle.ApplyStyle(tb.BackgroundStyle);
ctl.BackgroundStyle.Class = tb.BackgroundStyle.Class;
tb.ButtonClear.CopyToItem(ctl.ButtonClear);
tb.ButtonCustom.CopyToItem(ctl.ButtonCustom);
tb.ButtonCustom2.CopyToItem(ctl.ButtonCustom2);
tb.ButtonDropDown.CopyToItem(ctl.ButtonDropDown);
ctl.ButtonClearClick += ButtonClearClick;
ctl.ButtonCustomClick += ButtonCustomClick;
ctl.ButtonCustom2Click += ButtonCustom2Click;
ctl.ButtonDropDownClick += ButtonDropDownClick;
ctl.KeyDown += KeyDown;
ctl.Text = GetValue(initialFormattedValue);
ctl.BeepOnError = tb.BeepOnError;
}
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewMaskedTextBoxAdvEditingControl di =
DataGridView.EditingControl as DataGridViewMaskedTextBoxAdvEditingControl;
if (di != null)
{
di.ButtonClearClick -= ButtonClearClick;
di.ButtonCustomClick -= ButtonCustomClick;
di.ButtonCustom2Click -= ButtonCustom2Click;
di.ButtonDropDownClick -= ButtonDropDownClick;
di.KeyDown -= KeyDown;
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region ButtonClearClick
/// <summary>
/// ButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClearClick(object sender, CancelEventArgs e)
{
((DataGridViewMaskedTextBoxAdvColumn)OwningColumn).DoButtonClearClick(sender, e);
}
#endregion
#region ButtonCustomClick
/// <summary>
/// ButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustomClick(object sender, EventArgs e)
{
((DataGridViewMaskedTextBoxAdvColumn)OwningColumn).DoButtonCustomClick(sender, e);
}
#endregion
#region ButtonCustom2Click
/// <summary>
/// ButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustom2Click(object sender, EventArgs e)
{
((DataGridViewMaskedTextBoxAdvColumn)OwningColumn).DoButtonCustom2Click(sender, e);
}
#endregion
#region ButtonDropDownClick
/// <summary>
/// ButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonDropDownClick(object sender, CancelEventArgs e)
{
((DataGridViewMaskedTextBoxAdvColumn)OwningColumn).DoButtonDropDownClick(sender, e);
}
#endregion
#region KeyDown
/// <summary>
/// KeyDown routine forwards all DataGridView sent keys to
/// the underlying focusable control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void KeyDown(object sender, KeyEventArgs e)
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewMaskedTextBoxAdvEditingControl di =
DataGridView.EditingControl as DataGridViewMaskedTextBoxAdvEditingControl;
if (di != null)
{
di.MaskedTextBox.SelectAll();
PostMessage(di.MaskedTextBox.Handle, 256, (int) e.KeyCode, 1);
}
}
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (cellStyle.WrapMode != DataGridViewTriState.True)
{
if (r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height)/2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Height = Math.Max(1, r.Height);
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
if (DataGridView == null)
return (new Size(-1, -1));
Size preferredSize = base.GetPreferredSize(graphics, cellStyle, rowIndex, constraintSize);
DataGridViewMaskedTextBoxAdvColumn oc = OwningColumn as DataGridViewMaskedTextBoxAdvColumn;
if (oc != null)
{
MaskedTextBoxAdv msk = oc.MaskedTextBoxAdv;
preferredSize.Height = msk.Height;
if (constraintSize.Width == 0)
{
preferredSize.Width += GetImageWidth(msk.ButtonClear);
preferredSize.Width += GetImageWidth(msk.ButtonCustom);
preferredSize.Width += GetImageWidth(msk.ButtonCustom2);
preferredSize.Width += GetImageWidth(msk.ButtonDropDown);
}
}
return (preferredSize);
}
#endregion
#region GetFormattedValue
protected override object GetFormattedValue(object value, int rowIndex,
ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter,
TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
DataGridViewMaskedTextBoxAdvColumn oc = OwningColumn as DataGridViewMaskedTextBoxAdvColumn;
if (oc != null)
{
MaskedTextBoxAdv msk = oc.MaskedTextBoxAdv;
msk.Text = GetValue(value);
return (msk.Text);
}
return (base.GetFormattedValue(value, rowIndex,
ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context));
}
#endregion
#region GetImageWidth
private int GetImageWidth(InputButtonSettings ibs)
{
if (ibs.Visible == true)
return (ibs.Image != null ? ibs.Image.Width : 16);
return (0);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewMaskedTextBoxAdvColumn oc = (DataGridViewMaskedTextBoxAdvColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, formattedValue, cellStyle, paintParts, bm);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="bm"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Bitmap bm)
{
DataGridViewMaskedTextBoxAdvColumn oc = (DataGridViewMaskedTextBoxAdvColumn)OwningColumn;
MaskedTextBoxAdv di = oc.MaskedTextBoxAdv;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = cellStyle.BackColor;
di.TextAlign = GetTextAlignment(cellStyle.Alignment);
di.Text = GetValue(value);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, cellStyle, r, bm, g, oc);
else
DrawText(di, cellStyle, r, g);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="cellStyle"></param>
/// <param name="r"></param>
/// <param name="bm"></param>
/// <param name="g"></param>
/// <param name="oc"></param>
private void DrawControl(MaskedTextBoxAdv di, DataGridViewCellStyle cellStyle, Rectangle r,
Bitmap bm, Graphics g, DataGridViewMaskedTextBoxAdvColumn oc)
{
if (di.ButtonGroup.Items.Count > 0)
{
// Determine if we must perform some tom-foolery in order
// to get the control to DrawToBitmap correctly in older
// Windows versions
if (MustRenderVisibleControl() == true)
{
di.Location = oc.DataGridView.Location;
if (di.Parent == null)
{
Form form = oc.DataGridView.FindForm();
if (form != null)
di.Parent = form;
}
di.SendToBack();
di.Visible = true;
}
using (Bitmap bm2 = new Bitmap(bm))
{
di.Bounds = r;
di.DrawToBitmap(bm2, r);
foreach (VisualItem item in di.ButtonGroup.Items)
{
if (item.Visible == true)
{
Rectangle t = item.RenderBounds;
t.X += r.X;
t.Y += r.Y;
g.DrawImage(bm2, t, t, GraphicsUnit.Pixel);
if (t.Left < r.Right)
r.Width -= (r.Right - t.Left - 1);
}
}
}
di.Visible = false;
}
DrawText(di, cellStyle, r, g);
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="cellStyle"></param>
/// <param name="r"></param>
/// <param name="g"></param>
private void DrawText(MaskedTextBoxAdv di, DataGridViewCellStyle cellStyle, Rectangle r, Graphics g)
{
r.Inflate(-2, 0);
eTextFormat tf = eTextFormat.Default | eTextFormat.NoPrefix;
switch (di.TextAlign)
{
case HorizontalAlignment.Center:
tf |= eTextFormat.HorizontalCenter;
break;
case HorizontalAlignment.Right:
tf |= eTextFormat.Right;
break;
}
if (cellStyle.WrapMode == DataGridViewTriState.True)
tf |= eTextFormat.WordBreak;
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.TopLeft:
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.TopRight:
tf |= eTextFormat.Top;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
tf |= eTextFormat.Bottom;
break;
default:
tf |= eTextFormat.VerticalCenter;
break;
}
DataGridViewMaskedTextBoxAdvColumn oc = (DataGridViewMaskedTextBoxAdvColumn)OwningColumn;
string text = di.Text;
if (oc.PasswordChar != '\0')
text = "".PadRight(text.Length, oc.PasswordChar);
TextDrawing.DrawString(g, text, di.Font, di.ForeColor, r, tf);
}
#endregion
#endregion
#endregion
#region MustRenderVisibleControl
/// <summary>
/// MustRenderVisibleControl
/// </summary>
/// <returns></returns>
private bool MustRenderVisibleControl()
{
OperatingSystem osInfo = Environment.OSVersion;
return (osInfo.Platform == PlatformID.Win32Windows ||
(osInfo.Platform == PlatformID.Win32NT && osInfo.Version.Major < 6));
}
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewMaskedTextBoxAdvColumn oc = (DataGridViewMaskedTextBoxAdvColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewMaskedTextBoxAdvColumn oc = (DataGridViewMaskedTextBoxAdvColumn)OwningColumn;
Size size = oc.MaskedTextBoxAdv.PreferredSize;
cellBounds.Location = new Point(1, 1);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = size.Height - 1;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private string GetValue(object value)
{
return ((value != Convert.DBNull ? Convert.ToString(value) : ""));
}
#endregion
#region GetTextAlignment
/// <summary>
/// GetTextAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private HorizontalAlignment GetTextAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (HorizontalAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (HorizontalAlignment.Right);
default:
return (HorizontalAlignment.Left);
}
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,924 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewMaskedTextBoxAdvColumn), "Controls.MaskedTextBoxAdv.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewMaskedTextBoxAdvColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a MaskedTextBoxAdv Cell is painted
/// </summary>
[Description("Occurs right before a MaskedTextBoxAdv Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
/// <summary>
/// Occurs when Clear button is clicked and allows you
/// to cancel the default action performed by the button
/// </summary>
[Description("Occurs when Clear button is clicked and allows you to cancel the default action performed by the button.")]
public event EventHandler<CancelEventArgs> ButtonClearClick;
/// <summary>
/// Occurs when ButtonCustom control is clicked
/// </summary>
[Description("Occurs when ButtonCustom control is clicked.")]
public event EventHandler<EventArgs> ButtonCustomClick;
/// <summary>
/// Occurs when ButtonCustom2 control is clicked
/// </summary>
[Description("Occurs when ButtonCustom2 control is clicked.")]
public event EventHandler<EventArgs> ButtonCustom2Click;
/// <summary>
/// Occurs when Drop-Down button is clicked and allows you to cancel showing of the popup
/// </summary>
[Description("Occurs when Drop-Down button is clicked and allows you to cancel showing of the popup.")]
public event EventHandler<CancelEventArgs> ButtonDropDownClick;
#endregion
#region Private variables
private MaskedTextBoxAdv _MaskedTextBoxAdv;
private Bitmap _CellBitmap;
private bool _DisplayControlForCurrentCellOnly = true;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewMaskedTextBoxAdvColumn()
{
CellTemplate = new DataGridViewMaskedTextBoxAdvCell();
_MaskedTextBoxAdv = new MaskedTextBoxAdv();
_MaskedTextBoxAdv.BackgroundStyle.Class = ElementStyleClassKeys.DataGridViewBorderKey;
}
#region Internal properties
#region MaskedTextBoxAdv
/// <summary>
/// Gets the underlying MaskedTextBoxAdv control
/// </summary>
[Browsable(false)]
internal MaskedTextBoxAdv MaskedTextBoxAdv
{
get { return (_MaskedTextBoxAdv); }
}
#endregion
#endregion
#region Public properties
#region AllowPromptAsInput
/// <summary>
/// Gets or sets a value indicating whether PromptChar can be entered as valid data.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether PromptChar can be entered as valid data.")]
public bool AllowPromptAsInput
{
get { return (_MaskedTextBoxAdv.AllowPromptAsInput); }
set { _MaskedTextBoxAdv.AllowPromptAsInput = value; }
}
#endregion
#region AsciiOnly
/// <summary>
/// Gets or sets a value indicating whether characters outside of the ASCII character set will be accepted.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether whether characters outside of the ASCII character set will be accepted.")]
public bool AsciiOnly
{
get { return (_MaskedTextBoxAdv.AsciiOnly); }
set { _MaskedTextBoxAdv.AsciiOnly = value; }
}
#endregion
#region BackColor
/// <summary>
/// Gets or sets the Background color.
/// </summary>
[Browsable(false)]
public Color BackColor
{
get { return (_MaskedTextBoxAdv.BackColor); }
set { _MaskedTextBoxAdv.BackColor = value; }
}
#endregion
#region BackgroundStyle
/// <summary>
/// Specifies the background style of the control.
/// </summary>
[Browsable(true), Category("Style")]
[Description("Gets or sets control background style.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle BackgroundStyle
{
get { return (_MaskedTextBoxAdv.BackgroundStyle); }
}
/// <summary>
/// Resets style to default value. Used by windows forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundStyle()
{
_MaskedTextBoxAdv.ResetBackgroundStyle();
_MaskedTextBoxAdv.BackgroundStyle.Class = "TextBoxBorder";
_MaskedTextBoxAdv.BackgroundStyle.CornerType = eCornerType.Square;
}
#endregion
#region BeepOnError
/// <summary>
/// Gets or sets a value indicating whether the masked text box
/// control raises the system beep for each user key stroke that it rejects.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether the masked text box control raises the system beep for each user key stroke that it rejects.")]
public bool BeepOnError
{
get { return (_MaskedTextBoxAdv.BeepOnError); }
set { _MaskedTextBoxAdv.BeepOnError = value; }
}
#endregion
#region ButtonClear
/// <summary>
/// Gets the object that describes the settings for the button
/// that clears the content of the control when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that clears the content of the control when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonClear
{
get { return (_MaskedTextBoxAdv.ButtonClear); }
}
#endregion
#region ButtonCustom
/// <summary>
/// Gets the object that describes the settings for the custom button
/// that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom
{
get { return (_MaskedTextBoxAdv.ButtonCustom); }
}
#endregion
#region ButtonCustom2
/// <summary>
/// Gets the object that describes the settings for the custom button that can execute an custom action of your choosing when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the custom button that can execute an custom action of your choosing when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonCustom2
{
get { return (_MaskedTextBoxAdv.ButtonCustom2); }
}
#endregion
#region ButtonDropDown
/// <summary>
/// Gets the object that describes the settings for the button
/// that shows drop-down when clicked.
/// </summary>
[Browsable(true), Category("Buttons")]
[Description("Describes the settings for the button that shows drop-down when clicked.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public InputButtonSettings ButtonDropDown
{
get { return (_MaskedTextBoxAdv.ButtonDropDown); }
}
#endregion
#region Culture
/// <summary>
/// Gets or sets the culture information associated with the masked text box.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates the culture information associated with the masked text box.")]
public CultureInfo Culture
{
get { return (_MaskedTextBoxAdv.Culture); }
set { _MaskedTextBoxAdv.Culture = value; }
}
#endregion
#region CutCopyMaskFormat
/// <summary>
/// Gets or sets a value that determines whether
/// literals and prompt characters are copied to the clipboard
/// </summary>
[Browsable(true), DefaultValue(MaskFormat.IncludeLiterals)]
[Description("Indicates whether literals and prompt characters are copied to the clipboard.")]
public MaskFormat CutCopyMaskFormat
{
get { return (_MaskedTextBoxAdv.CutCopyMaskFormat); }
set { _MaskedTextBoxAdv.CutCopyMaskFormat = value; }
}
#endregion
#region DisplayControlForCurrentCellOnly
/// <summary>
/// Gets or sets whether the control
/// will be displayed for the current cell only.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether the control will be displayed for the current cell only.")]
public bool DisplayControlForCurrentCellOnly
{
get { return (_DisplayControlForCurrentCellOnly); }
set
{
if (_DisplayControlForCurrentCellOnly != value)
{
_DisplayControlForCurrentCellOnly = value;
_MaskedTextBoxAdv.Invalidate();
}
}
}
#endregion
#region DropDownControl
/// <summary>
/// Gets or sets the reference of the control that will be
/// displayed on popup that is shown when the drop-down button is clicked.
/// </summary>
[DefaultValue(null)]
[Description("Indicates reference of the control that will be displayed on popup that is shown when the drop-down button is clicked.")]
public Control DropDownControl
{
get { return (_MaskedTextBoxAdv.DropDownControl); }
set { _MaskedTextBoxAdv.DropDownControl = value; }
}
#endregion
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_MaskedTextBoxAdv.Enabled); }
set { _MaskedTextBoxAdv.Enabled = value; }
}
#endregion
#region FocusHighlightColor
/// <summary>
/// Gets or sets the color used as background color to highlight
/// the text box when it has input focus and FocusHighlight is enabled.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates color used as background color to highlight the text box when it has input focus and FocusHighlight is enabled.")]
public Color FocusHighlightColor
{
get { return (_MaskedTextBoxAdv.FocusHighlightColor); }
set { _MaskedTextBoxAdv.FocusHighlightColor = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeFocusHighlightColor()
{
return (_MaskedTextBoxAdv.ShouldSerializeFocusHighlightColor());
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetFocusHighlightColor()
{
_MaskedTextBoxAdv.ResetFocusHighlightColor();
}
#endregion
#region FocusHighlightEnabled
/// <summary>
/// Gets or sets whether FocusHighlightColor is used as
/// background color to highlight the text box when it has
/// input focus. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Appearance")]
[Description("Indicates whether FocusHighlightColor is used as background color to highlight the text box when it has input focus.")]
public bool FocusHighlightEnabled
{
get { return (_MaskedTextBoxAdv.FocusHighlightEnabled); }
set { _MaskedTextBoxAdv.FocusHighlightEnabled = value; }
}
#endregion
#region ForeColor
/// <summary>
/// Gets or sets the foreground color.
/// </summary>
[Browsable(false)]
public Color ForeColor
{
get { return (_MaskedTextBoxAdv.ForeColor); }
set { _MaskedTextBoxAdv.ForeColor = value; }
}
#endregion
#region HidePromptOnLeave
/// <summary>
/// Gets or sets a value indicating whether the prompt characters
/// in the input mask are hidden when the masked text box loses focus.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether the prompt characters in the input mask are hidden when the masked text box loses focus.")]
public bool HidePromptOnLeave
{
get { return (_MaskedTextBoxAdv.HidePromptOnLeave); }
set { _MaskedTextBoxAdv.HidePromptOnLeave = value; }
}
#endregion
#region ImeMode
/// <summary>
/// Gets or sets the Input Method Editor (IME) mode of the control.
/// </summary>
[Browsable(true), DefaultValue(ImeMode.Inherit)]
[Description("Indicates the Input Method Editor (IME) mode of the control.")]
public ImeMode ImeMode
{
get { return (_MaskedTextBoxAdv.ImeMode); }
set { _MaskedTextBoxAdv.ImeMode = value; }
}
#endregion
#region InsertKeyMode
/// <summary>
/// Gets or sets the text insertion mode of the masked text box control.
/// </summary>
[Browsable(true), DefaultValue(InsertKeyMode.Default)]
[Description("Indicates the text insertion mode of the masked text box control.")]
public InsertKeyMode InsertKeyMode
{
get { return (_MaskedTextBoxAdv.InsertKeyMode); }
set { _MaskedTextBoxAdv.InsertKeyMode = value; }
}
#endregion
#region Mask
/// <summary>
/// Gets or sets the input mask to use at run time.
/// </summary>
[Browsable(true), DefaultValue(null)]
[Description("Indicates the input mask to use at run time.")]
public string Mask
{
get { return (_MaskedTextBoxAdv.Mask); }
set { _MaskedTextBoxAdv.Mask = value; }
}
#endregion
#region PasswordChar
/// <summary>
/// Gets or sets the character to be displayed in substitute for user input.
/// </summary>
[Browsable(true), DefaultValue(null)]
[Description("Indicates the character to be displayed in substitute for user input.")]
public char PasswordChar
{
get { return (_MaskedTextBoxAdv.PasswordChar); }
set { _MaskedTextBoxAdv.PasswordChar = value; }
}
#endregion
#region PromptChar
/// <summary>
/// Gets or sets the character used to represent the absence of user input.
/// </summary>
[Browsable(true), DefaultValue('_')]
[Description("Indicates the character used to represent the absence of user input.")]
public char PromptChar
{
get { return (_MaskedTextBoxAdv.PromptChar); }
set { _MaskedTextBoxAdv.PromptChar = value; }
}
#endregion
#region RejectInputOnFirstFailure
/// <summary>
/// Gets or sets a value indicating whether the parsing of
/// user input should stop after the first invalid character is reached.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates the parsing of user input should stop after the first invalid character is reached.")]
public bool RejectInputOnFirstFailure
{
get { return (_MaskedTextBoxAdv.RejectInputOnFirstFailure); }
set { _MaskedTextBoxAdv.RejectInputOnFirstFailure = value; }
}
#endregion
#region ResetOnPrompt
/// <summary>
/// Gets or sets a value that determines how an input
/// character that matches the prompt character should be handled.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates how an input character that matches the prompt character should be handled.")]
public bool ResetOnPrompt
{
get { return (_MaskedTextBoxAdv.ResetOnPrompt); }
set { _MaskedTextBoxAdv.ResetOnPrompt = value; }
}
#endregion
#region ResetOnSpace
/// <summary>
/// Gets or sets a value that determines how
/// a space input character should be handled.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates how a space input character should be handled.")]
public bool ResetOnSpace
{
get { return (_MaskedTextBoxAdv.ResetOnSpace); }
set { _MaskedTextBoxAdv.ResetOnSpace = value; }
}
#endregion
#region RightToLeft
/// <summary>
/// Gets or sets a value indicating whether control's
/// elements are aligned to support locales using right-to-left fonts.
/// </summary>
[Browsable(true), DefaultValue(RightToLeft.Inherit)]
[Description("Indicates the control's elements are aligned to support locales using right-to-left fonts.")]
public RightToLeft RightToLeft
{
get { return (_MaskedTextBoxAdv.RightToLeft); }
set { _MaskedTextBoxAdv.RightToLeft = value; }
}
#endregion
#region SkipLiterals
/// <summary>
/// Gets or sets a value indicating
/// whether the user is allowed to reenter literal values.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates the user is allowed to reenter literal values.")]
public bool SkipLiterals
{
get { return (_MaskedTextBoxAdv.SkipLiterals); }
set { _MaskedTextBoxAdv.SkipLiterals = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text as it is currently displayed to the user.
/// </summary>
[Browsable(false)]
public string Text
{
get { return (_MaskedTextBoxAdv.Text); }
set { _MaskedTextBoxAdv.Text = value; }
}
#endregion
#region TextAlign
/// <summary>
/// Gets or sets how text is aligned in a masked text box control.
/// </summary>
[Browsable(true), DefaultValue(HorizontalAlignment.Left)]
[Description("Indicates how text is aligned in a masked text box control.")]
public HorizontalAlignment TextAlign
{
get { return (_MaskedTextBoxAdv.TextAlign); }
set { _MaskedTextBoxAdv.TextAlign = value; }
}
#endregion
#region TextMaskFormat
/// <summary>
/// Gets or sets a value that determines whether literals
/// and prompt characters are included in the formatted string.
/// </summary>
[Browsable(true), DefaultValue(MaskFormat.IncludeLiterals)]
[Description("Indicates whether literals and prompt characters are included in the formatted string.")]
public MaskFormat TextMaskFormat
{
get { return (_MaskedTextBoxAdv.TextMaskFormat); }
set { _MaskedTextBoxAdv.TextMaskFormat = value; }
}
#endregion
#region UseSystemPasswordChar
/// <summary>
/// Gets or sets a value indicating whether
/// the operating system-supplied password character should be used.
/// </summary>
[Browsable(true), DefaultValue(false)]
[Description("Indicates whether the operating system-supplied password character should be used.")]
public bool UseSystemPasswordChar
{
get { return (_MaskedTextBoxAdv.UseSystemPasswordChar); }
set { _MaskedTextBoxAdv.UseSystemPasswordChar = value; }
}
#endregion
#region ValidatingType
/// <summary>
/// Gets or sets the data type used to verify the data input by the user.
/// </summary>
[Browsable(false), DefaultValue(null)]
[Description("Indicates the data type used to verify the data input by the user.")]
public Type ValidatingType
{
get { return (_MaskedTextBoxAdv.ValidatingType); }
set { _MaskedTextBoxAdv.ValidatingType = value; }
}
#endregion
#region WatermarkBehavior
/// <summary>
/// Gets or sets the watermark hiding behaviour. Default value
/// indicates that watermark is hidden when control receives input focus.
/// </summary>
[Browsable(true), DefaultValue(eWatermarkBehavior.HideOnFocus), Category("Behavior")]
[Description("Indicates watermark hiding behaviour.")]
public eWatermarkBehavior WatermarkBehavior
{
get { return (_MaskedTextBoxAdv.WatermarkBehavior); }
set { _MaskedTextBoxAdv.WatermarkBehavior = value; }
}
#endregion
#region WatermarkColor
/// <summary>
/// Gets or sets the watermark text color.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates watermark text color.")]
public Color WatermarkColor
{
get { return (_MaskedTextBoxAdv.WatermarkColor); }
set { _MaskedTextBoxAdv.WatermarkColor = value; }
}
/// <summary>
/// Indicates whether property should be serialized by Windows Forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeWatermarkColor()
{
return (_MaskedTextBoxAdv.ShouldSerializeWatermarkColor());
}
/// <summary>
/// Resets the property to default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetWatermarkColor()
{
_MaskedTextBoxAdv.ResetWatermarkColor();
}
#endregion
#region WatermarkEnabled
/// <summary>
/// Gets or sets whether watermark text is
/// displayed when control is empty. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true)]
[Description("Indicates whether watermark text is displayed when control is empty.")]
public virtual bool WatermarkEnabled
{
get { return (_MaskedTextBoxAdv.WatermarkEnabled); }
set { _MaskedTextBoxAdv.WatermarkEnabled = value; }
}
#endregion
#region WatermarkFont
/// <summary>
/// Gets or sets the watermark font.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates watermark font.")]
public Font WatermarkFont
{
get { return (_MaskedTextBoxAdv.WatermarkFont); }
set { _MaskedTextBoxAdv.WatermarkFont = value; }
}
#endregion
#region WatermarkText
/// <summary>
/// Gets or sets the watermark (tip) text displayed inside of
/// the control when Text is not set and control does not have
/// input focus. This property supports text-markup.
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates watermark text displayed inside of the control when Text is not set and control does not have input focus.")]
[Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
public string WatermarkText
{
get { return (_MaskedTextBoxAdv.WatermarkText); }
set { _MaskedTextBoxAdv.WatermarkText = value; }
}
#endregion
#endregion
#region Event processing
#region DoButtonClearClick
/// <summary>
/// DoButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonClearClick(object sender, CancelEventArgs e)
{
if (ButtonClearClick != null)
ButtonClearClick(this, e);
}
#endregion
#region DoButtonCustomClick
/// <summary>
/// DoButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustomClick(object sender, EventArgs e)
{
if (ButtonCustomClick != null)
ButtonCustomClick(this, e);
}
#endregion
#region DoButtonCustom2Click
/// <summary>
/// DoButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonCustom2Click(object sender, EventArgs e)
{
if (ButtonCustom2Click != null)
ButtonCustom2Click(this, e);
}
#endregion
#region DoButtonDropDownClick
/// <summary>
/// DoButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
internal void DoButtonDropDownClick(object sender, CancelEventArgs e)
{
if (ButtonDropDownClick != null)
ButtonDropDownClick(this, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewMaskedTextBoxAdvColumn dc = base.Clone() as DataGridViewMaskedTextBoxAdvColumn;
if (dc != null)
{
dc.AllowPromptAsInput = AllowPromptAsInput;
dc.AsciiOnly = AsciiOnly;
dc.BeepOnError = BeepOnError;
dc.Culture = Culture;
dc.CutCopyMaskFormat = CutCopyMaskFormat;
dc.DropDownControl = DropDownControl;
dc.Enabled = Enabled;
dc.FocusHighlightColor = FocusHighlightColor;
dc.FocusHighlightEnabled = FocusHighlightEnabled;
dc.HidePromptOnLeave = HidePromptOnLeave;
dc.ImeMode = ImeMode;
dc.InsertKeyMode = InsertKeyMode;
dc.Mask = Mask;
dc.PasswordChar = PasswordChar;
dc.PromptChar = PromptChar;
dc.RejectInputOnFirstFailure = RejectInputOnFirstFailure;
dc.ResetOnPrompt = ResetOnPrompt;
dc.ResetOnSpace = ResetOnSpace;
dc.RightToLeft = RightToLeft;
dc.SkipLiterals = SkipLiterals;
dc.TextAlign = TextAlign;
dc.TextMaskFormat = TextMaskFormat;
dc.UseSystemPasswordChar = UseSystemPasswordChar;
dc.ValidatingType = ValidatingType;
dc.WatermarkBehavior = WatermarkBehavior;
dc.WatermarkColor = WatermarkColor;
dc.WatermarkEnabled = WatermarkEnabled;
dc.WatermarkFont = WatermarkFont;
dc.WatermarkText = WatermarkText;
dc.DisplayControlForCurrentCellOnly = DisplayControlForCurrentCellOnly;
dc.BackgroundStyle.ApplyStyle(MaskedTextBoxAdv.BackgroundStyle);
dc.BackgroundStyle.Class = MaskedTextBoxAdv.BackgroundStyle.Class;
MaskedTextBoxAdv.ButtonClear.CopyToItem(dc.MaskedTextBoxAdv.ButtonClear);
MaskedTextBoxAdv.ButtonDropDown.CopyToItem(dc.MaskedTextBoxAdv.ButtonDropDown);
MaskedTextBoxAdv.ButtonCustom.CopyToItem(dc.MaskedTextBoxAdv.ButtonCustom);
MaskedTextBoxAdv.ButtonCustom2.CopyToItem(dc.MaskedTextBoxAdv.ButtonCustom2);
}
return (dc);
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
if (disposing == true)
_MaskedTextBoxAdv.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
}
}

View File

@@ -0,0 +1,185 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewMaskedTextBoxAdvEditingControl : MaskedTextBoxAdv, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
#endregion
#region OnTextChanged
/// <summary>
/// Handles OnTextChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(EventArgs e)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
base.OnTextChanged(e);
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set { _DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get { return (Text); }
set { Text = (string) value; }
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (base.Cursor); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
ForeColor = dataGridViewCellStyle.ForeColor;
BackColor = dataGridViewCellStyle.BackColor;
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (EditingControlFormattedValue);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
return (dataGridViewWantsInputKey == false);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,402 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewProgressBarXCell : DataGridViewButtonCell
{
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (null); }
}
#endregion
#region FormattedValueType
/// <summary>
/// FormattedValueType
/// </summary>
public override Type FormattedValueType
{
get { return (typeof(string)); }
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintButtonBackground(g, cellStyle, rBk);
PaintButtonContent(cellBounds, rowIndex, formattedValue, cellStyle, paintParts, bm);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintButtonBackground
/// <summary>
/// Paints the Button background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintButtonBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false,
false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintButtonContent
/// <summary>
/// Paints the button background and content
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="bm"></param>
private void PaintButtonContent(Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Bitmap bm)
{
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
ProgressBarX bx = oc.ProgressBarX;
Rectangle rBt = GetContentBounds(cellBounds, true);
if (rBt.Width > 0 && rBt.Height > 0)
{
string s = oc.Text;
oc.InCallBack = true;
try
{
bx.Font = cellStyle.Font;
bx.ForeColor = cellStyle.ForeColor;
bx.BackColor = cellStyle.BackColor;
bx.Value = GetValue(value, bx.Minimum);
if (rowIndex < DataGridView.RowCount)
{
bx.Text = s;
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
}
else
{
bx.Text = "";
}
bx.Bounds = rBt;
bx.RecalcLayout();
bx.DrawToBitmap(bm, rBt);
}
finally
{
oc.InCallBack = false;
}
}
}
#endregion
#endregion
#region Mouse processing
#region OnMouseEnter
/// <summary>
/// OnMouseEnter
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseEnter(int rowIndex)
{
base.OnMouseEnter(rowIndex);
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn) OwningColumn;
ProgressBarX bx = oc.ProgressBarX;
bx.ProgressBarItem.InternalMouseEnter();
}
#endregion
#region OnMouseLeave
/// <summary>
/// Processes MouseLeave events
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseLeave(int rowIndex)
{
base.OnMouseLeave(rowIndex);
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
ProgressBarX bx = oc.ProgressBarX;
bx.ProgressBarItem.InternalMouseLeave();
}
#endregion
#region OnMouseMove
/// <summary>
/// Processes MouseMove events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
{
base.OnMouseMove(e);
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
ProgressBarX bx = oc.ProgressBarX;
bx.ProgressBarItem.InternalMouseMove(
new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta));
}
#endregion
#region OnMouseDown
/// <summary>
/// Processes MouseDown events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
{
base.OnMouseDown(e);
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
ProgressBarX bx = oc.ProgressBarX;
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
Rectangle rBt = GetContentBounds(cellBounds, false);
Point pt = e.Location;
pt.Offset(rBt.Location);
if (rBt.Contains(pt) == true)
{
bx.Bounds = rBt;
bx.ProgressBarItem.InternalMouseDown(
new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta));
DataGridView.Invalidate(rBt);
}
}
#endregion
#region OnMouseUp
/// <summary>
/// Processes MouseUp events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
{
base.OnMouseUp(e);
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
ProgressBarX bx = oc.ProgressBarX;
Rectangle cellBounds = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false);
Rectangle rBt = GetContentBounds(cellBounds, false);
bx.Bounds = rBt;
bx.ProgressBarItem.InternalMouseUp(
new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta));
DataGridView.Invalidate(rBt);
}
#endregion
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetContentBounds
/// <summary>
/// Gets the content bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="localize"></param>
/// <returns></returns>
private Rectangle GetContentBounds(Rectangle cellBounds, bool localize)
{
DataGridViewProgressBarXColumn oc = (DataGridViewProgressBarXColumn)OwningColumn;
cellBounds.Width -= (oc.DividerWidth + 3);
cellBounds.Height -= 3;
if (localize == true)
cellBounds.Location = new Point(0, 0);
cellBounds.X++;
cellBounds.Y++;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <param name="minimum"></param>
/// <returns></returns>
private int GetValue(object value, int minimum)
{
if (value == Convert.DBNull ||
(value is string && String.IsNullOrEmpty((string) value) == true))
{
return (minimum);
}
return (Convert.ToInt32(value));
}
#endregion
}
}

View File

@@ -0,0 +1,433 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "Controls.ProgressBarX.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewProgressBarXColumn : DataGridViewButtonColumn, IDataGridViewColumn
{
#region Events
[Description("Occurs right before a ProgressBarX Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
[Description("Occurs when a ProgressBarX Cell is Clicked.")]
public event EventHandler<EventArgs> Click;
#endregion
#region Private variables
private ProgressBarX _ProgressBarX;
private Bitmap _CellBitmap;
private bool _InCellCallBack;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewProgressBarXColumn()
{
CellTemplate = new DataGridViewProgressBarXCell();
_ProgressBarX = new ProgressBarX();
_ProgressBarX.Visible = false;
HookEvents(true);
}
#region Hidden properties
/// <summary>
/// Button FlatStyle
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new FlatStyle FlatStyle
{
get { return base.FlatStyle; }
set { base.FlatStyle = value; }
}
/// <summary>
/// Button UseColumnTextForButtonValue
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new bool UseColumnTextForButtonValue
{
get { return base.UseColumnTextForButtonValue; }
set { base.UseColumnTextForButtonValue = value; }
}
#endregion
#region Internal properties
#region InCallBack
/// <summary>
/// InCallBack
/// </summary>
internal bool InCallBack
{
get { return (_InCellCallBack); }
set { _InCellCallBack = value; }
}
#endregion
#region ProgressBarX
/// <summary>
/// Gets the Control ProgressBarX
/// </summary>
internal ProgressBarX ProgressBarX
{
get { return (_ProgressBarX); }
}
#endregion
#endregion
#region Public properties
#region ChunkColor
/// <summary>
/// Gets or sets the color of the progress chunk.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance")]
[Description("Gets or sets the color of the progress chunk.")]
public Color ChunkColor
{
get { return (_ProgressBarX.ChunkColor); }
set { _ProgressBarX.ChunkColor = value; }
}
/// <summary>
/// Gets whether ChunkColor property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeChunkColor()
{
return (_ProgressBarX.ChunkColor.IsEmpty == false);
}
/// <summary>
/// Resets the ChunkColor property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetChunkColor()
{
_ProgressBarX.ChunkColor = Color.Empty;
}
#endregion
#region ChunkColor2
/// <summary>
/// Gets or sets the target gradient color of the progress chunk.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance")]
[Description("Gets or sets the target gradient color of the progress chunk.")]
public Color ChunkColor2
{
get { return (_ProgressBarX.ChunkColor2); }
set { _ProgressBarX.ChunkColor2 = value; }
}
/// <summary>
/// Gets whether ChunkColor property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeChunkColor2()
{
return (_ProgressBarX.ChunkColor2.IsEmpty == false);
}
/// <summary>
/// Resets the ChunkColor property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetChunkColor2()
{
_ProgressBarX.ChunkColor2 = Color.Empty;
}
#endregion
#region ChunkGradientAngle
/// <summary>
/// Gets or sets the gradient angle of the progress chunk.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(0), Category("Appearance")]
[Description("Gets or sets the gradient angle of the progress chunk.")]
public int ChunkGradientAngle
{
get { return (_ProgressBarX.ChunkGradientAngle); }
set { _ProgressBarX.ChunkGradientAngle = value; }
}
#endregion
#region ColorTable
/// <summary>
/// Gets or sets the predefined color state table for progress bar. Color
/// specified applies to items with Office 2007 style only. It does not have
/// any effect on other styles. You can use ColorTable to indicate the state
/// of the operation that Progress Bar is tracking. Default value is eProgressBarItemColor.Normal.
/// </summary>
[Browsable(true), DevCoBrowsable(false), DefaultValue(eProgressBarItemColor.Normal), Category("Appearance")]
[Description("Indicates predefined color of item when Office 2007 style is used.")]
public eProgressBarItemColor ColorTable
{
get { return (_ProgressBarX.ColorTable); }
set { _ProgressBarX.ColorTable = value; }
}
#endregion
#region Maximum
/// <summary>
/// Gets or sets the maximum value of the range of the control.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(100)]
[Description("Indicates the maximum value of the range of the control.")]
public int Maximum
{
get { return (_ProgressBarX.Maximum); }
set { _ProgressBarX.Maximum = value; }
}
#endregion
#region Minimum
/// <summary>
/// Gets or sets the minimum value of the range of the control.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Behavior"), DefaultValue(0)]
[Description("Indicates the minimum value of the range of the control.")]
public int Minimum
{
get { return (_ProgressBarX.Minimum); }
set { _ProgressBarX.Minimum = value; }
}
#endregion
#region Style
/// <summary>
/// Gets/Sets the visual style for the control.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(eDotNetBarStyle.Office2007)]
[Description("Specifies the visual style of the control.")]
public virtual eDotNetBarStyle Style
{
get { return (_ProgressBarX.Style); }
set { _ProgressBarX.Style = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the default Text to display on the Progress Bar
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue("")]
[Description("Indicates the default Text to display on the Progress Bar.")]
public new string Text
{
get
{
return (_InCellCallBack == true ?
_ProgressBarX.Text : base.Text);
}
set
{
if (_InCellCallBack == true)
_ProgressBarX.Text = value;
else
base.Text = value;
}
}
#endregion
#region TextVisible
/// <summary>
/// Gets or sets whether the text inside the progress bar is displayed.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(false)]
[Description("Gets or sets whether the text inside the progress bar is displayed.")]
public bool TextVisible
{
get { return (_ProgressBarX.TextVisible); }
set { _ProgressBarX.TextVisible = value; }
}
#endregion
#region Value
/// <summary>
/// Gets or sets the current position of the progress bar.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Behavior"), DefaultValue(0)]
[Description("Indicates the current position of the progress bar.")]
public int Value
{
get { return (_ProgressBarX.Value); }
set { _ProgressBarX.Value = value; }
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// Hooks or unhooks our system events
/// </summary>
/// <param name="hook"></param>
private void HookEvents(bool hook)
{
if (hook == true)
{
_ProgressBarX.ProgressBarItem.Click += ProgressBarItem_Click;
}
else
{
_ProgressBarX.ProgressBarItem.Click -= ProgressBarItem_Click;
}
}
#endregion
#region Event processing
#region ProgressBarItem_Click
/// <summary>
/// ProgressBarItem_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ProgressBarItem_Click(object sender, EventArgs e)
{
if (Click != null)
Click(sender, e);
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewProgressBarXColumn bc = base.Clone() as DataGridViewProgressBarXColumn;
if (bc != null)
_ProgressBarX.ProgressBarItem.InternalCopyToItem(bc.ProgressBarX.ProgressBarItem);
return (bc);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the ButtonX control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
HookEvents(false);
if (disposing == true)
_ProgressBarX.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
}
}

View File

@@ -0,0 +1,604 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewSliderCell : DataGridViewTextBoxCell
{
#region Private variables
private DataGridViewCellStyle _CellStyle;
#endregion
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (null); }
}
#endregion
#region ValueType
/// <summary>
/// Gets the type of the underlying data
/// (i.e., the type of the cell's Value property)
/// </summary>
public override Type ValueType
{
get { return (base.ValueType ?? typeof(Int32)); }
}
#endregion
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetContentBounds(editingControlBounds);
if (r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height) / 2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
editingControlBounds.Height = Math.Max(1, r.Height);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
#region GetPreferredSize
/// <summary>
/// GetPreferredSize
/// </summary>
/// <param name="graphics"></param>
/// <param name="cellStyle"></param>
/// <param name="rowIndex"></param>
/// <param name="constraintSize"></param>
/// <returns></returns>
protected override Size GetPreferredSize(Graphics graphics,
DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
{
Size preferredSize = new Size(-1, -1);
if (DataGridView != null)
{
DataGridViewSliderColumn oc = OwningColumn as DataGridViewSliderColumn;
if (oc != null)
{
Slider sc = oc.Slider;
preferredSize.Height = sc.Height;
if (constraintSize.Width == 0)
{
preferredSize.Width += 80;
if (sc.LabelVisible == true)
preferredSize.Width += sc.LabelWidth;
}
}
}
return (preferredSize);
}
#endregion
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewSliderColumn oc = (DataGridViewSliderColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintSliderBackground(g, cellStyle, rBk);
PaintSliderContent(cellBounds, rowIndex, formattedValue, cellStyle, paintParts, g);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintSliderBackground
/// <summary>
/// Paints the Slider background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintSliderBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false, false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintSliderContent
/// <summary>
/// Paints the Slider content
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="g"></param>
private void PaintSliderContent(Rectangle cellBounds,
int rowIndex, object value, DataGridViewCellStyle cellStyle,
DataGridViewPaintParts paintParts, Graphics g)
{
DataGridViewSliderColumn oc = (DataGridViewSliderColumn) OwningColumn;
Slider slider = oc.Slider;
_CellStyle = cellStyle;
int saveValue = slider.Value;
eSliderPart mouseOverPart = slider.SliderItem.MouseOverPart;
eSliderPart mouseDownPart = slider.SliderItem.MouseDownPart;
GraphicsState gs = g.Save();
try
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
if (rowIndex != oc.ActiveRowIndex)
{
slider.SliderItem.MouseOverPart = eSliderPart.None;
slider.SliderItem.MouseDownPart = eSliderPart.None;
}
slider.Font = cellStyle.Font;
slider.ForeColor = cellStyle.ForeColor;
slider.BackColor = Selected ? Color.Transparent : cellStyle.BackColor;
if (rowIndex < DataGridView.RowCount)
{
slider.Text = oc.Text;
if (rowIndex != oc.ActiveRowIndex)
slider.Value = GetSliderValue(value);
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
}
else
{
slider.Text = "";
slider.Value = GetSliderValue(value);
}
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
g.TranslateTransform(r.X, r.Y);
slider.CallBasePaintBackground = false;
slider.Bounds = r;
slider.InternalPaint(new PaintEventArgs(g, Rectangle.Empty));
}
finally
{
g.Restore(gs);
slider.Value = saveValue;
slider.SliderItem.MouseOverPart = mouseOverPart;
slider.SliderItem.MouseDownPart = mouseDownPart;
}
}
#endregion
#endregion
#region Mouse processing
#region OnMouseEnter
/// <summary>
/// OnMouseEnter
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseEnter(int rowIndex)
{
base.OnMouseEnter(rowIndex);
DoMouseEnter(rowIndex, true);
}
#region DoMouseEnter
/// <summary>
/// Process MouseEnter state
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="refresh"></param>
private void DoMouseEnter(int rowIndex, bool refresh)
{
DataGridViewSliderColumn oc = (DataGridViewSliderColumn) OwningColumn;
Slider slider = oc.Slider;
// Work around an issue where we get notified of a mouse enter, but
// we will fault if we try to get the Value associated with the cell
if (Visible == true)
{
oc.ActiveRowIndex = rowIndex;
slider.Value = GetSliderValue(Value);
slider.SliderItem.InternalMouseEnter();
if (refresh == true)
RefreshSlider(ColumnIndex, rowIndex);
}
}
#endregion
#endregion
#region OnMouseLeave
/// <summary>
/// Processes MouseLeave events
/// </summary>
/// <param name="rowIndex"></param>
protected override void OnMouseLeave(int rowIndex)
{
base.OnMouseLeave(rowIndex);
DataGridViewSliderColumn oc = (DataGridViewSliderColumn)OwningColumn;
Slider slider = oc.Slider;
if (oc.ActiveRowIndex >= 0)
{
oc.ActiveRowIndex = -1;
slider.SliderItem.InternalMouseLeave();
Value = slider.Value;
RefreshSlider(ColumnIndex, rowIndex);
}
}
#endregion
#region OnMouseMove
/// <summary>
/// Processes MouseMove events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
{
base.OnMouseMove(e);
DataGridViewSliderColumn oc = OwningColumn as DataGridViewSliderColumn;
if (oc != null)
{
// Work around an issue where we get notified of a mouse enter / move, but
// we will fault if we try to get the Value associated with the cell
if (oc.ActiveRowIndex == -1)
DoMouseEnter(e.RowIndex, false);
if (oc.ActiveRowIndex >= 0)
{
Point pt = CellAlignPoint(e.X, e.Y);
oc.Slider.SliderItem.InternalMouseMove(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
RefreshSlider(e.ColumnIndex, e.RowIndex);
}
}
}
#endregion
#region OnMouseDown
/// <summary>
/// Processes MouseDown events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseDown(DataGridViewCellMouseEventArgs e)
{
base.OnMouseDown(e);
DataGridViewSliderColumn oc = OwningColumn as DataGridViewSliderColumn;
if (oc != null)
{
Point pt = CellAlignPoint(e.X, e.Y);
oc.Slider.SliderItem.InternalMouseDown(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
RefreshSlider(e.ColumnIndex, e.RowIndex);
}
}
#endregion
#region OnMouseUp
/// <summary>
/// Processes MouseUp events
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(DataGridViewCellMouseEventArgs e)
{
base.OnMouseUp(e);
DataGridViewSliderColumn oc = OwningColumn as DataGridViewSliderColumn;
if (oc != null)
{
Point pt = CellAlignPoint(e.X, e.Y);
oc.Slider.SliderItem.InternalMouseUp(
new MouseEventArgs(e.Button, e.Clicks, pt.X, pt.Y, e.Delta));
Value = oc.Slider.Value;
RefreshSlider(e.ColumnIndex, e.RowIndex);
}
}
#endregion
#region CellAlignPoint
/// <summary>
/// CellAlignPoint
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
private Point CellAlignPoint(int x, int y)
{
Rectangle r = GetAdjustedEditingControlBounds(ContentBounds, _CellStyle);
return (new Point(x, y - r.Y));
}
#endregion
#endregion
#region GetSliderValue
/// <summary>
/// GetSliderValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
internal int GetSliderValue(object value)
{
if (value == Convert.DBNull ||
(value is string && String.IsNullOrEmpty((string) value) == true))
{
return (0);
}
return (Convert.ToInt32(value));
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewSliderColumn oc = (DataGridViewSliderColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetContentBounds
/// <summary>
/// Gets the content bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetContentBounds(Rectangle cellBounds)
{
DataGridViewSliderColumn oc = (DataGridViewSliderColumn)OwningColumn;
if (oc.Slider.Parent == null)
{
Form form = oc.DataGridView.FindForm();
if (form != null)
oc.Slider.Parent = form;
}
oc.Slider.SliderItem.RecalcSize();
cellBounds.Width -= (oc.DividerWidth + 3);
cellBounds.Height = oc.Slider.SliderItem.HeightInternal;
return (cellBounds);
}
#endregion
#region RefreshSlider
/// <summary>
/// Initiates the refresh of the cell slider
/// </summary>
/// <param name="columnIndex"></param>
/// <param name="rowIndex"></param>
internal void RefreshSlider(int columnIndex, int rowIndex)
{
if (DataGridView != null)
DataGridView.InvalidateCell(columnIndex, rowIndex);
}
#endregion
}
}

View File

@@ -0,0 +1,462 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(DataGridViewButtonXColumn), "Controls.Slider.ico"), ToolboxItem(false), ComVisible(false)]
public class DataGridViewSliderColumn : DataGridViewTextBoxColumn, IDataGridViewColumn
{
#region Events
/// <summary>
/// Occurs right before a Slider Cell is painted
/// </summary>
[Description("Occurs right before a Slider Cell is painted.")]
public event EventHandler<BeforeCellPaintEventArgs> BeforeCellPaint;
[Description("Occurs when a Slider Cell is Clicked.")]
public event EventHandler<EventArgs> Click;
#endregion
#region Private variables
private Slider _Slider;
private Bitmap _CellBitmap;
private int _ActiveRowIndex = -1;
private bool _BindingComplete;
#endregion
/// <summary>
/// Constructor
/// </summary>
public DataGridViewSliderColumn()
{
CellTemplate = new DataGridViewSliderCell();
_Slider = new Slider();
_Slider.Visible = false;
HookEvents(true);
}
#region Internal properties
#region ActiveRowIndex
/// <summary>
/// Gets or sets the active row index
/// </summary>
internal int ActiveRowIndex
{
get { return (_ActiveRowIndex); }
set { _ActiveRowIndex = value; }
}
#endregion
#region BindingComplete
/// <summary>
/// Gets or sets the DataBindingComplete state
/// </summary>
internal bool BindingComplete
{
get { return (_BindingComplete); }
set { _BindingComplete = value; }
}
#endregion
#region Slider
/// <summary>
/// Gets the Control Slider
/// </summary>
internal Slider Slider
{
get { return (_Slider); }
}
#endregion
#endregion
#region Public properties
#region Enabled
/// <summary>
/// Gets or sets whether the control can respond to user interaction
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behavior")]
[Description("Indicates whether the control can respond to user interaction.")]
public bool Enabled
{
get { return (_Slider.Enabled); }
set { _Slider.Enabled = value; }
}
#endregion
#region EnableMarkup
/// <summary>
/// Gets or sets whether text-markup support is enabled for items Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the item instead of it being parsed as text-markup.
/// </summary>
[DefaultValue(true), Category("Appearance")]
[Description("Indicates whether text-markup support is enabled for items Text property.")]
public bool EnableMarkup
{
get { return (_Slider.EnableMarkup); }
set { _Slider.EnableMarkup = value; }
}
#endregion
#region LabelPosition
/// <summary>
/// Gets or sets the text label position in relationship to the slider. Default value is Left.
/// </summary>
[Browsable(true), DefaultValue(eSliderLabelPosition.Left), Category("Layout")]
[Description("Indicates text label position in relationship to the slider")]
public eSliderLabelPosition LabelPosition
{
get { return (_Slider.LabelPosition); }
set { _Slider.LabelPosition = value; }
}
#endregion
#region LabelVisible
/// <summary>
/// Gets or sets whether the text label next to the slider is displayed.
/// </summary>
[DevCoBrowsable(true), Browsable(true)]
[Description("Gets or sets whether the label text is displayed."), Category("Behavior"), DefaultValue(true)]
public bool LabelVisible
{
get { return (_Slider.LabelVisible); }
set { _Slider.LabelVisible = value; }
}
#endregion
#region LabelWidth
/// <summary>
/// Gets or sets the width of the label part of the item in pixels. Value must be greater than 0. Default value is 38.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(38), Category("Layout")]
[Description("Indicates width of the label part of the item in pixels.")]
public int LabelWidth
{
get { return (_Slider.LabelWidth); }
set { _Slider.LabelWidth = value; }
}
#endregion
#region Maximum
/// <summary>
/// Gets or sets the maximum value of the range of the control.
/// </summary>
[DevCoBrowsable(true), Browsable(true), Category("Behavior"), DefaultValue(100)]
[Description("Gets or sets the maximum value of the range of the control.")]
public int Maximum
{
get { return (_Slider.Maximum); }
set { _Slider.Maximum = value; }
}
#endregion
#region Minimum
/// <summary>
/// Gets or sets the minimum value of the range of the control.
/// </summary>
[DevCoBrowsable(true), Browsable(true), Category("Behavior"), DefaultValue(0)]
[Description("Gets or sets the minimum value of the range of the control.")]
public int Minimum
{
get { return (_Slider.Minimum); }
set { _Slider.Minimum = value; }
}
#endregion
#region Step
/// <summary>
/// Gets or sets the amount by which a call to the PerformStep method increases the current position of the slider. Value must be greater than 0.
/// </summary>
[DevCoBrowsable(true), Browsable(true), Category("Behavior"), DefaultValue(1)]
[Description("Gets or sets the amount by which a call to the PerformStep method increases the current position of the slider.")]
public int Step
{
get { return (_Slider.Step); }
set { _Slider.Step = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text associated with this item.
/// </summary>
[Browsable(false), DevCoBrowsable(false), DefaultValue(""), Category("Appearance")]
[Description("The text contained in the item.")]
public string Text
{
get { return (_Slider.Text); }
set { _Slider.Text = value; }
}
#endregion
#region TextColor
/// <summary>
/// Gets or sets the color of the label text.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates color of the label text.")]
public Color TextColor
{
get { return (_Slider.TextColor); }
set { _Slider.TextColor = value; }
}
/// <summary>
/// Returns whether property should be serialized. Used by Windows Forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTextColor()
{
return (_Slider.TextColor.IsEmpty == false);
}
/// <summary>
/// Resets the property to default value. Used by Windows Forms designer.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTextColor()
{
_Slider.TextColor = Color.Empty;
}
#endregion
#region TrackMarker
/// <summary>
/// Gets or sets whether vertical line track marker is displayed on the slide line. Default value is true.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(true)]
[Description("Indicates whether vertical line track marker is displayed on the slide line.")]
public virtual bool TrackMarker
{
get { return (_Slider.TrackMarker); }
set { _Slider.TrackMarker = value; }
}
#endregion
#region Value
/// <summary>
/// Gets or sets the current position of the slider.
/// </summary>
[Browsable(false)]
[Description("Indicates the current position of the slider.")]
public int Value
{
get { return (_Slider.Value); }
set { _Slider.Value = value; }
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// Hooks or unhooks our system events
/// </summary>
/// <param name="hook"></param>
private void HookEvents(bool hook)
{
if (hook == true)
{
_Slider.SliderItem.Click += SliderItem_Click;
_Slider.SliderItem.ValueChanged += SliderItem_ValueChanged;
}
else
{
_Slider.SliderItem.Click -= SliderItem_Click;
_Slider.SliderItem.ValueChanged -= SliderItem_ValueChanged;
}
}
#endregion
#region Event processing
#region SliderItem_Click
/// <summary>
/// SliderItem_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SliderItem_Click(object sender, EventArgs e)
{
if (Click != null)
Click(sender, e);
}
#endregion
#region SliderItem_ValueChanged
/// <summary>
/// SliderItem_ValueChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SliderItem_ValueChanged(object sender, EventArgs e)
{
if (_Slider.SliderItem.MouseDownPart == eSliderPart.IncreaseButton ||
_Slider.SliderItem.MouseDownPart == eSliderPart.DecreaseButton)
{
DataGridViewSliderCell cell = DataGridView.Rows[ActiveRowIndex].Cells[Index] as DataGridViewSliderCell;
if (cell != null)
{
int value = cell.GetSliderValue(cell.Value);
if (value != _Slider.SliderItem.Value)
{
cell.Value = _Slider.SliderItem.Value;
cell.RefreshSlider(Index, ActiveRowIndex);
}
}
}
}
#endregion
#endregion
#region GetCellBitmap
/// <summary>
/// Gets the cell paint bitmap
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
internal Bitmap GetCellBitmap(Rectangle cellBounds)
{
if (_CellBitmap == null ||
(_CellBitmap.Width != cellBounds.Width || _CellBitmap.Height < cellBounds.Height))
{
if (_CellBitmap != null)
_CellBitmap.Dispose();
_CellBitmap = new Bitmap(cellBounds.Width, cellBounds.Height);
}
return (_CellBitmap);
}
#endregion
#region OnBeforeCellPaint
/// <summary>
/// Invokes BeforeCellPaint user events
/// </summary>
/// <param name="rowIndex">Row index</param>
/// <param name="columnIndex">Column index</param>
internal void OnBeforeCellPaint(int rowIndex, int columnIndex)
{
if (BeforeCellPaint != null)
BeforeCellPaint(this, new BeforeCellPaintEventArgs(rowIndex, columnIndex));
}
#endregion
#region ICloneable members
/// <summary>
/// Clones the ButtonX Column
/// </summary>
/// <returns></returns>
public override object Clone()
{
DataGridViewSliderColumn sc = base.Clone() as DataGridViewSliderColumn;
if (sc != null)
{
_Slider.SliderItem.InternalCopyToItem(sc.Slider.SliderItem);
sc.Enabled = Enabled;
}
return (sc);
}
#endregion
#region IDataGridViewColumn Members
/// <summary>
/// Gets the Cell paint setting for the ButtonX control
/// </summary>
[Browsable(false)]
public bool OwnerPaintCell
{
get { return (true); }
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
HookEvents(false);
if (disposing == true)
_Slider.Dispose();
if (_CellBitmap != null)
{
_CellBitmap.Dispose();
_CellBitmap = null;
}
base.Dispose(disposing);
}
#endregion
}
}

View File

@@ -0,0 +1,670 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using DevComponents.Editors;
namespace DevComponents.DotNetBar.Controls
{
public class DataGridViewTextBoxDropDownCell : DataGridViewTextBoxCell
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
#region Public properties
#region EditType
/// <summary>
/// Gets the Type of the editing control associated with the cell
/// </summary>
public override Type EditType
{
get { return (typeof(DataGridViewTextBoxDropDownEditingControl)); }
}
#endregion
#endregion
#region InitializeEditingControl
/// <summary>
/// InitializeEditingControl
/// </summary>
/// <param name="rowIndex"></param>
/// <param name="initialFormattedValue"></param>
/// <param name="dataGridViewCellStyle"></param>
public override void InitializeEditingControl(int rowIndex,
object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
DetachEditingControl();
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
DataGridViewTextBoxDropDownEditingControl ctl =
(DataGridViewTextBoxDropDownEditingControl)DataGridView.EditingControl;
DataGridViewTextBoxDropDownColumn oc = (DataGridViewTextBoxDropDownColumn)OwningColumn;
TextBoxDropDown tb = oc.TextBoxDropDown;
ctl.AutoCompleteCustomSource = tb.AutoCompleteCustomSource;
ctl.AutoCompleteMode = tb.AutoCompleteMode;
ctl.AutoCompleteSource = tb.AutoCompleteSource;
ctl.BackColor = tb.BackColor;
ctl.CharacterCasing = tb.CharacterCasing;
ctl.DropDownControl = tb.DropDownControl;
ctl.Enabled = tb.Enabled;
ctl.FocusHighlightColor = tb.FocusHighlightColor;
ctl.FocusHighlightEnabled = tb.FocusHighlightEnabled;
ctl.ForeColor = tb.ForeColor;
ctl.HideSelection = tb.HideSelection;
ctl.ImeMode = tb.ImeMode;
ctl.MaxLength = tb.MaxLength;
ctl.PasswordChar = tb.PasswordChar;
ctl.RightToLeft = tb.RightToLeft;
ctl.TextAlign = GetTextAlignment(dataGridViewCellStyle.Alignment);
ctl.UseSystemPasswordChar = tb.UseSystemPasswordChar;
ctl.WatermarkBehavior = tb.WatermarkBehavior;
ctl.WatermarkColor = tb.WatermarkColor;
ctl.WatermarkEnabled = tb.WatermarkEnabled;
ctl.WatermarkFont = tb.WatermarkFont;
ctl.WatermarkText = tb.WatermarkText;
ctl.TextBox.Multiline = (dataGridViewCellStyle.WrapMode == DataGridViewTriState.True);
ctl.BackgroundStyle.ApplyStyle(tb.BackgroundStyle);
ctl.BackgroundStyle.Class = tb.BackgroundStyle.Class;
tb.ButtonClear.CopyToItem(ctl.ButtonClear);
tb.ButtonCustom.CopyToItem(ctl.ButtonCustom);
tb.ButtonCustom2.CopyToItem(ctl.ButtonCustom2);
tb.ButtonDropDown.CopyToItem(ctl.ButtonDropDown);
ctl.ButtonClearClick += ButtonClearClick;
ctl.ButtonCustomClick += ButtonCustomClick;
ctl.ButtonCustom2Click += ButtonCustom2Click;
ctl.ButtonDropDownClick += ButtonDropDownClick;
ctl.KeyDown += KeyDown;
ctl.Text = (initialFormattedValue != null && initialFormattedValue != Convert.DBNull
? Convert.ToString(initialFormattedValue) : "");
}
#endregion
#region DetachEditingControl
/// <summary>
/// DetachEditingControl
/// </summary>
public override void DetachEditingControl()
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewTextBoxDropDownEditingControl di =
DataGridView.EditingControl as DataGridViewTextBoxDropDownEditingControl;
if (di != null)
{
di.ButtonClearClick -= ButtonClearClick;
di.ButtonCustomClick -= ButtonCustomClick;
di.ButtonCustom2Click -= ButtonCustom2Click;
di.ButtonDropDownClick -= ButtonDropDownClick;
di.KeyDown -= KeyDown;
}
}
base.DetachEditingControl();
}
#endregion
#region Event processing
#region ButtonClearClick
/// <summary>
/// ButtonClearClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonClearClick(object sender, CancelEventArgs e)
{
((DataGridViewTextBoxDropDownColumn)OwningColumn).DoButtonClearClick(sender, e);
}
#endregion
#region ButtonCustomClick
/// <summary>
/// ButtonCustomClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustomClick(object sender, EventArgs e)
{
((DataGridViewTextBoxDropDownColumn)OwningColumn).DoButtonCustomClick(sender, e);
}
#endregion
#region ButtonCustom2Click
/// <summary>
/// ButtonCustom2Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonCustom2Click(object sender, EventArgs e)
{
((DataGridViewTextBoxDropDownColumn)OwningColumn).DoButtonCustom2Click(sender, e);
}
#endregion
#region ButtonDropDownClick
/// <summary>
/// ButtonDropDownClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ButtonDropDownClick(object sender, CancelEventArgs e)
{
((DataGridViewTextBoxDropDownColumn)OwningColumn).DoButtonDropDownClick(sender, e);
}
#endregion
#region KeyDown
/// <summary>
/// KeyDown routine forwards all DataGridView sent keys to
/// the underlying focusable control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void KeyDown(object sender, KeyEventArgs e)
{
if (DataGridView != null && DataGridView.EditingControl != null)
{
DataGridViewTextBoxDropDownEditingControl di =
DataGridView.EditingControl as DataGridViewTextBoxDropDownEditingControl;
if (di != null)
PostMessage(di.TextBox.Handle, 256, (int) e.KeyCode, 1);
}
}
#endregion
#endregion
#region PositionEditingControl
/// <summary>
/// PositionEditingControl
/// </summary>
/// <param name="setLocation"></param>
/// <param name="setSize"></param>
/// <param name="cellBounds"></param>
/// <param name="cellClip"></param>
/// <param name="cellStyle"></param>
/// <param name="singleVerticalBorderAdded"></param>
/// <param name="singleHorizontalBorderAdded"></param>
/// <param name="isFirstDisplayedColumn"></param>
/// <param name="isFirstDisplayedRow"></param>
public override void PositionEditingControl(bool setLocation, bool setSize, Rectangle cellBounds,
Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded,
bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
{
Rectangle editingControlBounds =
PositionEditingPanel(cellBounds, cellClip, cellStyle, singleVerticalBorderAdded,
singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
editingControlBounds = GetAdjustedEditingControlBounds(editingControlBounds, cellStyle);
DataGridView.EditingControl.Location = new Point(editingControlBounds.X, editingControlBounds.Y);
DataGridView.EditingControl.Size = new Size(editingControlBounds.Width, editingControlBounds.Height);
}
#endregion
#region GetAdjustedEditingControlBounds
/// <summary>
/// GetAdjustedEditingControlBounds
/// </summary>
/// <param name="editingControlBounds"></param>
/// <param name="cellStyle"></param>
/// <returns></returns>
private Rectangle GetAdjustedEditingControlBounds(
Rectangle editingControlBounds, DataGridViewCellStyle cellStyle)
{
// Add a 1 pixel padding around the editing control
editingControlBounds.X += 1;
editingControlBounds.Y += 1;
editingControlBounds.Width = Math.Max(0, editingControlBounds.Width - 2);
editingControlBounds.Height = Math.Max(0, editingControlBounds.Height - 2);
// Adjust the vertical location of the editing control
Rectangle r = GetCellBounds(editingControlBounds);
if (cellStyle.WrapMode != DataGridViewTriState.True)
{
if (r.Height < editingControlBounds.Height)
{
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.MiddleLeft:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.MiddleRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height)/2;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
editingControlBounds.Y += (editingControlBounds.Height - r.Height);
break;
}
}
editingControlBounds.Height = Math.Max(1, r.Height);
}
editingControlBounds.Width = Math.Max(1, editingControlBounds.Width);
return (editingControlBounds);
}
#endregion
#region GetPreferredSize
///// <summary>
///// GetPreferredSize
///// </summary>
///// <param name="graphics"></param>
///// <param name="cellStyle"></param>
///// <param name="rowIndex"></param>
///// <param name="constraintSize"></param>
///// <returns></returns>
//protected override Size GetPreferredSize(Graphics graphics,
// DataGridViewCellStyle cellStyle, int rowIndex, Size constraintSize)
//{
// if (DataGridView == null)
// return (new Size(-1, -1));
// DataGridViewTextBoxDropDownColumn oc = (DataGridViewTextBoxDropDownColumn)OwningColumn;
// Size size = oc.TextBoxDropDown.PreferredSize;
// size.Height += 3;
// return (size);
//}
#endregion
#region Paint
#region Paint
/// <summary>
/// Cell painting
/// </summary>
/// <param name="graphics"></param>
/// <param name="clipBounds"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="elementState"></param>
/// <param name="value"></param>
/// <param name="formattedValue"></param>
/// <param name="errorText"></param>
/// <param name="cellStyle"></param>
/// <param name="advancedBorderStyle"></param>
/// <param name="paintParts"></param>
protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates elementState, object value, object formattedValue,
string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{
if (DataGridView != null)
{
// First paint the borders of the cell
if (PartsSet(paintParts, DataGridViewPaintParts.Border))
PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
// Now paint the background and content
if (PartsSet(paintParts, DataGridViewPaintParts.Background))
{
Rectangle rBk = GetBackBounds(cellBounds, advancedBorderStyle);
if (rBk.Height > 0 && rBk.Width > 0)
{
DataGridViewTextBoxDropDownColumn oc = (DataGridViewTextBoxDropDownColumn)OwningColumn;
Bitmap bm = oc.GetCellBitmap(cellBounds);
if (bm != null)
{
using (Graphics g = Graphics.FromImage(bm))
{
PaintCellBackground(g, cellStyle, rBk);
PaintCellContent(g, cellBounds, rowIndex, formattedValue, cellStyle, paintParts, bm);
graphics.DrawImageUnscaledAndClipped(bm, rBk);
}
if ((DataGridView.ShowCellErrors == true) &&
(paintParts & DataGridViewPaintParts.ErrorIcon) == DataGridViewPaintParts.ErrorIcon)
{
base.PaintErrorIcon(graphics, clipBounds, cellBounds, errorText);
}
}
}
}
}
}
#endregion
#region PaintCellBackground
/// <summary>
/// Paints the cell background
/// </summary>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
/// <param name="rBack"></param>
private void PaintCellBackground(Graphics g,
DataGridViewCellStyle cellStyle, Rectangle rBack)
{
Rectangle r = rBack;
r.Location = new Point(0, 0);
DataGridViewX dx = DataGridView as DataGridViewX;
if (dx != null && dx.Enabled == true && Selected == true &&
dx.PaintEnhancedSelection == true)
{
Office2007ButtonItemPainter.PaintBackground(g, dx.ButtonStateColorTable,
r, RoundRectangleShapeDescriptor.RectangleShape, false, false);
}
else
{
Color color = (Selected == true)
? cellStyle.SelectionBackColor : cellStyle.BackColor;
using (Brush br = new SolidBrush(color))
g.FillRectangle(br, r);
}
}
#endregion
#region PaintCellContent
/// <summary>
/// Paints the cell content
/// </summary>
/// <param name="g"></param>
/// <param name="cellBounds"></param>
/// <param name="rowIndex"></param>
/// <param name="value"></param>
/// <param name="cellStyle"></param>
/// <param name="paintParts"></param>
/// <param name="bm"></param>
private void PaintCellContent(Graphics g, Rectangle cellBounds, int rowIndex, object value,
DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts, Bitmap bm)
{
DataGridViewTextBoxDropDownColumn oc = (DataGridViewTextBoxDropDownColumn)OwningColumn;
TextBoxDropDown di = oc.TextBoxDropDown;
Point ptCurrentCell = DataGridView.CurrentCellAddress;
bool cellCurrent = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
bool cellEdited = cellCurrent && DataGridView.EditingControl != null;
// If the cell is in editing mode, there is nothing else to paint
if (cellEdited == false && rowIndex < DataGridView.RowCount)
{
if (PartsSet(paintParts, DataGridViewPaintParts.ContentForeground))
{
cellBounds.X = 0;
cellBounds.Y = 0;
cellBounds.Width -= (oc.DividerWidth + 1);
cellBounds.Height -= 1;
di.Font = cellStyle.Font;
di.ForeColor = cellStyle.ForeColor;
di.BackColor = cellStyle.BackColor;
di.TextAlign = GetTextAlignment(cellStyle.Alignment);
di.Text = GetValue(value);
oc.OnBeforeCellPaint(rowIndex, ColumnIndex);
Rectangle r = GetAdjustedEditingControlBounds(cellBounds, cellStyle);
if (oc.DisplayControlForCurrentCellOnly == false)
DrawControl(di, cellStyle, r, bm, g);
else
DrawText(di, cellStyle, r, g);
}
}
}
#region DrawControl
/// <summary>
/// DrawControl
/// </summary>
/// <param name="di"></param>
/// <param name="cellStyle"></param>
/// <param name="r"></param>
/// <param name="bm"></param>
/// <param name="g"></param>
private void DrawControl(TextBoxDropDown di, DataGridViewCellStyle cellStyle, Rectangle r, Bitmap bm, Graphics g)
{
if (di.ButtonGroup.Items.Count > 0)
{
using (Bitmap bm2 = new Bitmap(bm))
{
di.Bounds = r;
di.DrawToBitmap(bm2, r);
foreach (VisualItem item in di.ButtonGroup.Items)
{
if (item.Visible == true)
{
Rectangle t = item.RenderBounds;
t.X += r.X;
t.Y += r.Y;
g.DrawImage(bm2, t, t, GraphicsUnit.Pixel);
if (t.Left < r.Right)
r.Width -= (r.Right - t.Left - 1);
}
}
}
}
DrawText(di, cellStyle, r, g);
}
#endregion
#region DrawText
/// <summary>
/// DrawText
/// </summary>
/// <param name="di"></param>
/// <param name="r"></param>
/// <param name="g"></param>
/// <param name="cellStyle"></param>
private void DrawText(TextBoxDropDown di, DataGridViewCellStyle cellStyle, Rectangle r, Graphics g)
{
r.Inflate(-2, 0);
eTextFormat tf = eTextFormat.Default | eTextFormat.NoPrefix;
switch (di.TextAlign)
{
case HorizontalAlignment.Center:
tf |= eTextFormat.HorizontalCenter;
break;
case HorizontalAlignment.Right:
tf |= eTextFormat.Right;
break;
}
if (cellStyle.WrapMode == DataGridViewTriState.True)
tf |= eTextFormat.WordBreak;
switch (cellStyle.Alignment)
{
case DataGridViewContentAlignment.TopLeft:
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.TopRight:
tf |= eTextFormat.Top;
break;
case DataGridViewContentAlignment.BottomLeft:
case DataGridViewContentAlignment.BottomCenter:
case DataGridViewContentAlignment.BottomRight:
tf |= eTextFormat.Bottom;
break;
default:
tf |= eTextFormat.VerticalCenter;
break;
}
TextDrawing.DrawString(g, di.Text, di.Font, di.ForeColor, r, tf);
}
#endregion
#endregion
#endregion
#region GetBackBounds
/// <summary>
/// Gets the background bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <param name="advancedBorderStyle"></param>
/// <returns></returns>
private Rectangle GetBackBounds(
Rectangle cellBounds, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
DataGridViewTextBoxDropDownColumn oc = (DataGridViewTextBoxDropDownColumn)OwningColumn;
Rectangle r = BorderWidths(advancedBorderStyle);
cellBounds.Offset(r.X, r.Y);
cellBounds.Width -= r.Right;
cellBounds.Height -= r.Bottom;
if (Selected == true)
cellBounds.Width += oc.DividerWidth;
return (cellBounds);
}
#endregion
#region GetCellBounds
/// <summary>
/// Gets the button bounds for the given cell
/// </summary>
/// <param name="cellBounds"></param>
/// <returns></returns>
private Rectangle GetCellBounds(Rectangle cellBounds)
{
DataGridViewTextBoxDropDownColumn oc = (DataGridViewTextBoxDropDownColumn)OwningColumn;
Size size = oc.TextBoxDropDown.PreferredSize;
cellBounds.Location = new Point(1, 1);
cellBounds.Width -= oc.DividerWidth;
cellBounds.Height = size.Height - 1;
return (cellBounds);
}
#endregion
#region GetValue
/// <summary>
/// GetValue
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private string GetValue(object value)
{
return (value != Convert.DBNull ? Convert.ToString(value) : "");
}
#endregion
#region GetTextAlignment
/// <summary>
/// GetTextAlignment
/// </summary>
/// <param name="alignment"></param>
/// <returns></returns>
private HorizontalAlignment GetTextAlignment(DataGridViewContentAlignment alignment)
{
switch (alignment)
{
case DataGridViewContentAlignment.TopCenter:
case DataGridViewContentAlignment.MiddleCenter:
case DataGridViewContentAlignment.BottomCenter:
return (HorizontalAlignment.Center);
case DataGridViewContentAlignment.TopRight:
case DataGridViewContentAlignment.MiddleRight:
case DataGridViewContentAlignment.BottomRight:
return (HorizontalAlignment.Right);
default:
return (HorizontalAlignment.Left);
}
}
#endregion
#region PartsSet
/// <summary>
/// Determines if the given part is set
/// </summary>
/// <param name="paintParts"></param>
/// <param name="parts"></param>
/// <returns></returns>
private bool PartsSet(DataGridViewPaintParts paintParts, DataGridViewPaintParts parts)
{
return ((paintParts & parts) == parts);
}
#endregion
}
}

View File

@@ -0,0 +1,185 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), ComVisible(false)]
public class DataGridViewTextBoxDropDownEditingControl : TextBoxDropDown, IDataGridViewEditingControl
{
#region Private variables
private DataGridView _DataGridView;
private int _RowIndex;
private bool _ValueChanged;
#endregion
#region OnTextChanged
/// <summary>
/// Handles OnTextChanged events
/// </summary>
/// <param name="e"></param>
protected override void OnTextChanged(EventArgs e)
{
_ValueChanged = true;
_DataGridView.NotifyCurrentCellDirty(true);
base.OnTextChanged(e);
}
#endregion
#region IDataGridViewEditingControl Members
#region Public properties
#region EditingControlDataGridView
/// <summary>
/// Gets or sets the DataGridView
/// </summary>
public DataGridView EditingControlDataGridView
{
get { return (_DataGridView); }
set { _DataGridView = value; }
}
#endregion
#region EditingControlFormattedValue
/// <summary>
/// Gets or sets the Control Formatted Value
/// </summary>
public object EditingControlFormattedValue
{
get { return (Text); }
set { Text = (string)value; }
}
#endregion
#region EditingControlRowIndex
/// <summary>
/// Gets or sets the Control RoeIndex
/// </summary>
public int EditingControlRowIndex
{
get { return (_RowIndex); }
set { _RowIndex = value; }
}
#endregion
#region EditingControlValueChanged
/// <summary>
/// Gets or sets the Control ValueChanged state
/// </summary>
public bool EditingControlValueChanged
{
get { return (_ValueChanged); }
set { _ValueChanged = value; }
}
#endregion
#region EditingPanelCursor
/// <summary>
/// Gets the Panel Cursor
/// </summary>
public Cursor EditingPanelCursor
{
get { return (base.Cursor); }
}
#endregion
#region RepositionEditingControlOnValueChange
/// <summary>
/// Gets whether to RepositionEditingControlOnValueChange
/// </summary>
public bool RepositionEditingControlOnValueChange
{
get { return (false); }
}
#endregion
#endregion
#region ApplyCellStyleToEditingControl
/// <summary>
/// ApplyCellStyleToEditingControl
/// </summary>
/// <param name="dataGridViewCellStyle"></param>
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
Font = dataGridViewCellStyle.Font;
ForeColor = dataGridViewCellStyle.ForeColor;
BackColor = dataGridViewCellStyle.BackColor;
}
#endregion
#region GetEditingControlFormattedValue
/// <summary>
/// Gets EditingControlFormattedValue
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return (EditingControlFormattedValue);
}
#endregion
#region EditingControlWantsInputKey
/// <summary>
/// Gets whether the given key wants to be processed
/// by the Control
/// </summary>
/// <param name="keyData"></param>
/// <param name="dataGridViewWantsInputKey"></param>
/// <returns></returns>
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if ((keyData & Keys.Right) == Keys.Right)
return (true);
if ((keyData & Keys.Left) == Keys.Left)
return (true);
return (dataGridViewWantsInputKey == false);
}
#endregion
#region PrepareEditingControlForEdit
/// <summary>
/// PrepareEditingControlForEdit
/// </summary>
/// <param name="selectAll"></param>
public void PrepareEditingControlForEdit(bool selectAll)
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,14 @@
namespace DevComponents.DotNetBar.Controls
{
internal interface IDataGridViewColumn
{
/// <summary>
/// Gets whether the Column cells will fully paint
/// their cell background and content
/// </summary>
bool OwnerPaintCell
{
get;
}
}
}

View File

@@ -0,0 +1,511 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Displays the desktop alerts with optional image or symbol. Text on alerts supports text-markup.
/// </summary>
public static class DesktopAlert
{
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
public static void Show(string text)
{
Show(text, _AlertColor, _AlertPosition, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="referenceControl">Specifies reference control which is used to find target screen alert is displayed on.</param>
public static void Show(string text, Control referenceControl)
{
Show(text, _AlertColor, _AlertPosition, null, referenceControl);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
public static void Show(string text, MarkupLinkClickEventHandler markupLinkClickHandler)
{
Show(text, _AlertColor, _AlertPosition, markupLinkClickHandler);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertColor">Specifies alert color.</param>
public static void Show(string text, eDesktopAlertColor alertColor)
{
Show(text, alertColor, _AlertPosition, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertColor">Specifies alert color.</param>
/// <param name="referenceControl">Specifies reference control which is used to find target screen alert is displayed on.</param>
public static void Show(string text, eDesktopAlertColor alertColor, Control referenceControl)
{
Show(text, alertColor, _AlertPosition, null, referenceControl);
}
/// <summary>
/// Shows desktop alert at specific screen position.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="position">Alert position on the screen.</param>
public static void Show(string text, eAlertPosition position)
{
Show(text, _AlertColor, position, null);
}
/// <summary>
/// Shows desktop alert at specific screen position.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="position">Alert position on the screen.</param>
/// <param name="referenceControl">Specifies reference control which is used to find target screen alert is displayed on.</param>
public static void Show(string text, eAlertPosition position, Control referenceControl)
{
Show(text, _AlertColor, position, null, referenceControl);
}
/// <summary>
/// Shows desktop alert at specific screen position.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="image">Image to display on alert.</param>
public static void Show(string text, Image image)
{
Show(text, image, _AlertColor, _AlertPosition, _AutoCloseTimeOut, 0, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertColor">Alert color.</param>
/// <param name="position">Alert position on the screen.</param>
public static void Show(string text, eDesktopAlertColor alertColor, eAlertPosition position)
{
Show(text, alertColor, position, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertColor">Alert color</param>
/// <param name="position">Alert position on the screen</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
/// <param name="referenceControl">Specifies reference control which is used to find target screen alert is displayed on.</param>
public static void Show(string text, eDesktopAlertColor alertColor, eAlertPosition position, MarkupLinkClickEventHandler markupLinkClickHandler, Control referenceControl)
{
DesktopAlertWindow alert = new DesktopAlertWindow();
alert.Text = text;
alert.MaximumSize = Dpi.Size(_MaximumAlertSize);
alert.AlertPosition = position;
alert.AutoCloseTimeOut = _AutoCloseTimeOut;
alert.TextMarkupEnabled = _TextMarkupEnabled;
if (markupLinkClickHandler != null)
alert.MarkupLinkClick += markupLinkClickHandler;
alert.AlertAnimationDuration = _AlertAnimationDuration;
alert.PlaySound = _PlaySound;
alert.ReferenceControl = referenceControl;
SetColors(alert, alertColor);
alert.Show();
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertColor">Alert color</param>
/// <param name="position">Alert position on the screen</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
public static void Show(string text, eDesktopAlertColor alertColor, eAlertPosition position, MarkupLinkClickEventHandler markupLinkClickHandler)
{
Show(text, alertColor, position, markupLinkClickHandler, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
public static void Show(string text, long alertId, Action<long> alertClickAction)
{
Show(text, null, _AlertColor, _AlertPosition, _AutoCloseTimeOut, alertId, alertClickAction);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="alertColor">Alert color</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
public static void Show(string text, eDesktopAlertColor alertColor, long alertId, Action<long> alertClickAction)
{
Show(text, null, alertColor, _AlertPosition, _AutoCloseTimeOut, alertId, alertClickAction);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="symbol">Symbol to show on the alert, see http://www.devcomponents.com/kb2/?p=1347 </param>
/// <param name="symbolSet">Symbol set to use</param>
/// <param name="symbolColor">Symbol color or Color.Empty to use default text color</param>
/// <param name="alertColor">Alert color</param>
/// <param name="position">Alert position on the screen</param>
/// <param name="alertDurationSeconds">Duration of alert in the seconds.</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
public static void Show(string text, string symbol, eSymbolSet symbolSet, Color symbolColor, eDesktopAlertColor alertColor, eAlertPosition position,
int alertDurationSeconds, long alertId, Action<long> alertClickAction)
{
Show(text, symbol, symbolSet, symbolColor, alertColor,position, alertDurationSeconds, alertId, alertClickAction, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="symbol">Symbol to show on the alert, see http://www.devcomponents.com/kb2/?p=1347 </param>
/// <param name="symbolSet">Symbol set to use</param>
/// <param name="symbolColor">Symbol color or Color.Empty to use default text color</param>
/// <param name="position">Alert position on the screen</param>
/// <param name="alertColor">Alert color</param>
/// <param name="alertDurationSeconds">Duration of alert in the seconds.</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
public static void Show(string text, string symbol, eSymbolSet symbolSet, Color symbolColor, eDesktopAlertColor alertColor, eAlertPosition position,
int alertDurationSeconds, long alertId, Action<long> alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler)
{
Show(text, symbol, symbolSet, symbolColor, alertColor, position, alertDurationSeconds, alertId, alertClickAction, markupLinkClickHandler, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="symbol">Symbol to show on the alert, see http://www.devcomponents.com/kb2/?p=1347 </param>
/// <param name="symbolSet">Symbol set to use</param>
/// <param name="symbolColor">Symbol color or Color.Empty to use default text color</param>
/// <param name="position">Alert position on the screen</param>
/// <param name="alertColor">Alert color</param>
/// <param name="alertDurationSeconds">Duration of alert in the seconds.</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
/// <param name="referenceControl">Specifies reference control which is used to find target screen alert is displayed on.</param>
public static void Show(string text, string symbol, eSymbolSet symbolSet, Color symbolColor, eDesktopAlertColor alertColor, eAlertPosition position,
int alertDurationSeconds, long alertId, Action<long> alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler, Control referenceControl)
{
DesktopAlertWindow alert = new DesktopAlertWindow();
alert.Text = text;
alert.MaximumSize = Dpi.Size(_MaximumAlertSize);
alert.AlertPosition = position;
alert.Symbol = symbol;
alert.SymbolSet = symbolSet;
alert.SymbolColor = symbolColor;
alert.AlertId = alertId;
alert.ClickAction = alertClickAction;
alert.AutoCloseTimeOut = alertDurationSeconds;
alert.TextMarkupEnabled = _TextMarkupEnabled;
if (markupLinkClickHandler != null)
alert.MarkupLinkClick += markupLinkClickHandler;
alert.AlertAnimationDuration = _AlertAnimationDuration;
alert.PlaySound = _PlaySound;
alert.ReferenceControl = referenceControl;
SetColors(alert, alertColor);
alert.Show();
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="image">Image to display on the alert</param>
/// <param name="position">Alert screen position</param>
/// <param name="alertColor">Alert color</param>
/// <param name="alertDurationSeconds">Duration of alert in seconds</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
public static void Show(string text, Image image, eDesktopAlertColor alertColor, eAlertPosition position,
int alertDurationSeconds, long alertId, Action<long> alertClickAction)
{
Show(text, image, alertColor, position, alertDurationSeconds, alertId, alertClickAction, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="image">Image to display on the alert</param>
/// <param name="position">Alert screen position</param>
/// <param name="alertColor">Alert color</param>
/// <param name="alertDurationSeconds">Duration of alert in seconds</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
public static void Show(string text, Image image, eDesktopAlertColor alertColor, eAlertPosition position,
int alertDurationSeconds, long alertId, Action<long> alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler)
{
Show(text, image, alertColor, position, alertDurationSeconds, alertId, alertClickAction, markupLinkClickHandler, null);
}
/// <summary>
/// Shows desktop alert.
/// </summary>
/// <param name="text">Text to show on the alert. Text supports text-markup.</param>
/// <param name="image">Image to display on the alert</param>
/// <param name="position">Alert screen position</param>
/// <param name="alertColor">Alert color</param>
/// <param name="alertDurationSeconds">Duration of alert in seconds</param>
/// <param name="alertId">Alert ID used to recognize alert if clicked and specified Action is called</param>
/// <param name="alertClickAction">Action method to call if alert is clicked.</param>
/// <param name="markupLinkClickHandler">Text-markup link click event handler.</param>
/// <param name="referenceControl">Specifies reference control which is used to find target screen alert is displayed on.</param>
public static void Show(string text, Image image, eDesktopAlertColor alertColor, eAlertPosition position,
int alertDurationSeconds, long alertId, Action<long> alertClickAction, MarkupLinkClickEventHandler markupLinkClickHandler, Control referenceControl)
{
DesktopAlertWindow alert = new DesktopAlertWindow();
alert.Text = text;
alert.MaximumSize = Dpi.Size(_MaximumAlertSize);
alert.AlertPosition = position;
alert.Image = image;
alert.AlertId = alertId;
alert.ClickAction = alertClickAction;
alert.AutoCloseTimeOut = alertDurationSeconds;
alert.TextMarkupEnabled = _TextMarkupEnabled;
if (markupLinkClickHandler != null)
alert.MarkupLinkClick += markupLinkClickHandler;
alert.AlertAnimationDuration = _AlertAnimationDuration;
alert.PlaySound = _PlaySound;
alert.ReferenceControl = referenceControl;
SetColors(alert, alertColor);
alert.Show();
}
private static void SetColors(DesktopAlertWindow w, eDesktopAlertColor c)
{
if (c == eDesktopAlertColor.Default)
{
w.BackColor = ColorScheme.GetColor(0x0078D7);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.Black)
{
w.BackColor = Color.Black;
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.Blue)
{
w.BackColor = ColorScheme.GetColor(0x5B9BD5);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.BlueGray)
{
w.BackColor = ColorScheme.GetColor(0x44546A);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.DarkBlue)
{
w.BackColor = ColorScheme.GetColor(0x4472C4);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.DarkRed)
{
w.BackColor = ColorScheme.GetColor(0xC00000);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.Gold)
{
w.BackColor = ColorScheme.GetColor(0xFFC000);
w.ForeColor = Color.Black;
}
else if (c == eDesktopAlertColor.Gray)
{
w.BackColor = ColorScheme.GetColor(0xE7E6E6);
w.ForeColor = Color.Black;
}
else if (c == eDesktopAlertColor.Green)
{
w.BackColor = ColorScheme.GetColor(0x375623);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.Orange)
{
w.BackColor = ColorScheme.GetColor(0xCA5010);
w.ForeColor = Color.White;
}
else if (c == eDesktopAlertColor.Red)
{
w.BackColor = ColorScheme.GetColor(0xE81123);
w.ForeColor = Color.White;
}
}
private static Size _MaximumAlertSize = new Size(400, 128);
/// <summary>
/// Indicates maximum alert size.
/// </summary>
public static Size MaximumAlertSize
{
get { return _MaximumAlertSize; }
set { _MaximumAlertSize = value; }
}
private static eAlertPosition _AlertPosition = eAlertPosition.BottomRight;
/// <summary>
/// Specifies default alert screen position.
/// </summary>
public static eAlertPosition AlertPosition
{
get { return _AlertPosition; }
set { _AlertPosition = value; }
}
private static eDesktopAlertColor _AlertColor = eDesktopAlertColor.Default;
/// <summary>
/// Specifies default alert color.
/// </summary>
public static eDesktopAlertColor AlertColor
{
get { return _AlertColor; }
set { _AlertColor = value; }
}
private static int _AlertAnimationDuration = 200;
/// <summary>
/// Gets or sets the total time in milliseconds alert animation takes.
/// Default value is 200.
/// </summary>
public static int AlertAnimationDuration
{
get { return _AlertAnimationDuration; }
set { _AlertAnimationDuration = value; }
}
private static int _AutoCloseTimeOut = 6;
/// <summary>
/// Gets or sets time period in seconds after alert closes automatically.
/// </summary>
public static int AutoCloseTimeOut
{
get { return _AutoCloseTimeOut; }
set { _AutoCloseTimeOut = value; }
}
private static bool _TextMarkupEnabled = true;
/// <summary>
/// Gets or sets whether text-markup can be used in alert text, default value is true.
/// </summary>
public static bool TextMarkupEnabled
{
get { return _TextMarkupEnabled; }
set { _TextMarkupEnabled = value; }
}
private static bool _PlaySound = true;
/// <summary>
/// Indicates whether alert plays exclamation sound when shown.
/// </summary>
public static bool PlaySound
{
get { return _PlaySound; }
set { _PlaySound = value; }
}
/// <summary>
/// Occurs before alert is displayed and allows access to the alert Window through sender.
/// </summary>
[Description("Occurs before alert is displayed and allows access to the alert Window through sender.")]
public static event EventHandler BeforeAlertDisplayed;
/// <summary>
/// Raises BeforeAlertDisplayed event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
internal static void OnBeforeAlertDisplayed(DesktopAlertWindow w, EventArgs e)
{
EventHandler h = BeforeAlertDisplayed;
if (h != null)
h(w, e);
}
/// <summary>
/// Occurs after alert as been closed.
/// </summary>
[Description("Occurs after alert has been closed.")]
public static event AlertClosedEventHandler AlertClosed;
/// <summary>
/// Raises RemovingToken event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
internal static void OnAlertClosed(object sender, AlertClosedEventArgs e)
{
AlertClosedEventHandler handler = AlertClosed;
if (handler != null)
handler(sender, e);
}
}
/// <summary>
/// Defines delegate for AlertClosed event.
/// </summary>
/// <param name="sender">Sender.</param>
/// <param name="args">Event arguments</param>
public delegate void AlertClosedEventHandler(object sender, AlertClosedEventArgs args);
/// <summary>
/// Defines event arguments for AlertClosed event.
/// </summary>
public class AlertClosedEventArgs : EventArgs
{
/// <summary>
/// Specifies alert closure source.
/// </summary>
public readonly eAlertClosureSource ClosureSource;
public AlertClosedEventArgs(eAlertClosureSource source)
{
ClosureSource = source;
}
}
/// <summary>
/// Defines predefined desktop alert colors.
/// </summary>
public enum eDesktopAlertColor
{
Default,
DarkRed,
Black,
Gray,
BlueGray,
Blue,
Orange,
Gold,
DarkBlue,
Green,
Red
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Defines colors for the Flyout control.
/// </summary>
public class FlyoutColorTable
{
/// <summary>
/// Specifies Flyout background color.
/// </summary>
public Color BackColor = Color.White;
/// <summary>
/// Specifies Flyout border color.
/// </summary>
public Color BorderColor = ColorScheme.GetColor(0x2B579A);
}
}

View File

@@ -0,0 +1,53 @@
namespace DevComponents.DotNetBar.Controls
{
partial class FlyoutForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// FlyoutForm
//
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FlyoutForm";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
}
}

View File

@@ -0,0 +1,323 @@
using DevComponents.DotNetBar.Rendering;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
public partial class FlyoutForm : Form
{
public FlyoutForm()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
InitializeComponent();
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.BackColor = Color.White;
//_PointerSide = ePointerSide.Top;
_PointerOffset = this.Width-50;
}
private int _PointerOffset;
private const int CS_DROPSHADOW = 0x00020000;
protected override CreateParams CreateParams
{
get
{
// add the drop shadow flag for automatically drawing
// a drop shadow around the form
CreateParams cp = base.CreateParams;
if(_DropShadow)
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
protected override bool ShowWithoutActivation
{
get
{
return !_ActivateOnShow;
}
}
private bool _DropShadow = true;
/// <summary>
/// Indicates whether flyout displays a drop shadow.
/// </summary>
[DefaultValue(true)]
public bool DropShadow
{
get { return _DropShadow; }
set
{
_DropShadow = value;
}
}
private bool _ActivateOnShow = false;
/// <summary>
/// Gets or sets whether form is made active/focused when shown.
/// </summary>
[DefaultValue(false)]
public bool ActivateOnShow
{
get { return _ActivateOnShow; }
set
{
_ActivateOnShow = value;
}
}
private GraphicsPath GetFormPath(Rectangle r)
{
return GetFormPath(r, false);
}
private static readonly Size _PointerSize = new Size(24, 12);
internal static Size PointerSize
{
get
{
return _PointerSize;
}
}
private GraphicsPath GetFormPath(Rectangle r, bool isBorder)
{
Size calloutSize = _PointerSize; // new Size(24, 12);
GraphicsPath path = new GraphicsPath();
if (_PointerSide == ePointerSide.Top)
{
int cX = Math.Min(Math.Max(3, _PointerOffset), r.Width - calloutSize.Width + 3); //r.Right - (calloutSize.Width + 10);
path.AddLine(r.X, r.Y + calloutSize.Height, cX + (isBorder ? 1 : 0), r.Y + calloutSize.Height);
path.AddLine(cX, r.Y + calloutSize.Height, cX + calloutSize.Width / 2, r.Y);
path.AddLine(cX + calloutSize.Width / 2, r.Y, cX + calloutSize.Width, r.Y + calloutSize.Height);
path.AddLine(cX + calloutSize.Width, r.Y + calloutSize.Height, r.Right, r.Y + calloutSize.Height);
path.AddLine(r.Right, r.Y + calloutSize.Height, r.Right, r.Bottom);
path.AddLine(r.Right, r.Bottom, r.X, r.Bottom);
path.AddLine(r.X, r.Bottom, r.X, r.Y + calloutSize.Height);
path.CloseAllFigures();
}
else if (_PointerSide == ePointerSide.Bottom)
{
int cX = Math.Min(Math.Max(3, _PointerOffset), r.Width - calloutSize.Width + 3); //r.Right - (calloutSize.Width + 10);
path.AddLine(r.X, r.Bottom - calloutSize.Height, cX + (isBorder ? 1 : 0), r.Bottom - calloutSize.Height);
path.AddLine(cX, r.Bottom - calloutSize.Height, cX + calloutSize.Width / 2, r.Bottom);
path.AddLine(cX + calloutSize.Width / 2, r.Bottom, cX + calloutSize.Width, r.Bottom - calloutSize.Height);
path.AddLine(cX + calloutSize.Width, r.Bottom - calloutSize.Height, r.Right, r.Bottom - calloutSize.Height);
path.AddLine(r.Right, r.Bottom - calloutSize.Height, r.Right, r.Y);
path.AddLine(r.Right, r.Y, r.X, r.Y);
path.AddLine(r.X, r.Y, r.X, r.Bottom - calloutSize.Height);
path.CloseAllFigures();
}
else if (_PointerSide == ePointerSide.Left)
{
int cY = Math.Min(Math.Max(3, _PointerOffset), r.Height - calloutSize.Width + 3); //r.Bottom - (calloutSize.Width + 10);
path.AddLine(r.X + calloutSize.Height, r.Bottom, r.X + calloutSize.Height, cY + (isBorder ? 1 : 0));
path.AddLine(r.X + calloutSize.Height, cY + (isBorder ? 1 : 0), r.X, cY + calloutSize.Width / 2);
path.AddLine(r.X, cY + calloutSize.Width / 2, r.X + calloutSize.Height, cY + calloutSize.Width);
path.AddLine(r.X + calloutSize.Height, cY + calloutSize.Width, r.X + calloutSize.Height, r.Y);
path.AddLine(r.X + calloutSize.Height, r.Y, r.Right, r.Y);
path.AddLine(r.Right, r.Y, r.Right, r.Bottom);
path.AddLine(r.Right, r.Bottom, r.X + calloutSize.Height, r.Bottom);
path.CloseAllFigures();
}
else if (_PointerSide == ePointerSide.Right)
{
int cY = Math.Min(Math.Max(3, _PointerOffset), r.Width - calloutSize.Height + 3); //r.Bottom - (calloutSize.Width + 10);
path.AddLine(r.Right - calloutSize.Height, r.Y, r.Right - calloutSize.Height, cY + (isBorder ? 1 : 0));
path.AddLine(r.Right - calloutSize.Height, cY + (isBorder ? 1 : 0), r.Right - (isBorder ? 1 : 0), cY + calloutSize.Width / 2);
path.AddLine(r.Right - (isBorder ? 1 : 0), cY + calloutSize.Width / 2, r.Right - calloutSize.Height, cY + calloutSize.Width);
path.AddLine(r.Right - calloutSize.Height, cY + calloutSize.Width, r.Right - calloutSize.Height, r.Bottom);
path.AddLine(r.Right - calloutSize.Height, r.Bottom, r.X, r.Bottom);
path.AddLine(r.X, r.Bottom, r.X, r.Y);
path.AddLine(r.X, r.Y, r.Right - calloutSize.Height, r.Y);
path.CloseAllFigures();
}
return path;
}
private Region GetFormRegion()
{
return new Region(GetFormPath(this.ClientRectangle));
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle r = this.ClientRectangle;
r.Inflate(-1, -1);
FlyoutColorTable table = GetColorTable();
Color backColor = this.BackColor;
if (backColor.IsEmpty)
backColor = table.BackColor;
Color borderColor = _BorderColor;
if(borderColor == Color.Empty)
{
borderColor = table.BorderColor;
}
using (GraphicsPath path = GetFormPath(r, true))
{
using(SolidBrush borderBrush=new SolidBrush(borderColor))
e.Graphics.FillRectangle(borderBrush, this.ClientRectangle);
e.Graphics.SetClip(path);
using (SolidBrush brush = new SolidBrush(backColor))
e.Graphics.FillRectangle(brush, this.ClientRectangle);
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
//e.Graphics.DrawPath(Pens.Red, path);
}
//base.OnPaint(e);
}
private FlyoutColorTable GetColorTable()
{
return ((Office2007Renderer)GlobalManager.Renderer).ColorTable.Flyout;
}
private void Form1_Load(object sender, EventArgs e)
{
//UpdateFormRegion();
}
protected override void OnHandleCreated(EventArgs e)
{
UpdateFormRegion();
base.OnHandleCreated(e);
}
protected override void OnResize(EventArgs e)
{
UpdateFormRegion();
base.OnResize(e);
}
private void UpdateFormRegion()
{
this.Region = GetFormRegion();
}
/// <summary>
/// Gets or sets the pointer offset from the top-left corner
/// </summary>
public int PointerOffset
{
get { return _PointerOffset; }
set
{
if (value !=_PointerOffset)
{
int oldValue = _PointerOffset;
_PointerOffset = value;
OnPointerOffsetChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when PointerOffset property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnPointerOffsetChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("PointerOffset"));
if (this.IsHandleCreated)
UpdateFormRegion();
}
private ePointerSide _PointerSide = ePointerSide.Bottom;
/// <summary>
/// Gets or sets the side pointer triangle is displayed on.
/// </summary>
public ePointerSide PointerSide
{
get { return _PointerSide; }
set
{
if (value != _PointerSide)
{
ePointerSide oldValue = _PointerSide;
_PointerSide = value;
OnPointerSideChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when PointerSide property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnPointerSideChanged(ePointerSide oldValue, ePointerSide newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("PointerSide"));
if (this.IsHandleCreated)
UpdateFormRegion();
}
private Color _BorderColor = Color.Empty;
/// <summary>
/// Gets or sets the flyout border color. Default value of Color.Empty indicates that color scheme will be used.
/// </summary>
[Category("Columns"), Description("Indicates flyout border color. Default value of Color.Empty indicates that color scheme will be used.")]
public Color BorderColor
{
get { return _BorderColor; }
set { _BorderColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeBorderColor()
{
return !_BorderColor.IsEmpty;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBorderColor()
{
this.BorderColor = Color.Empty;
}
private bool _IsActive = false;
protected override void OnActivated(EventArgs e)
{
_IsActive = true;
base.OnActivated(e);
}
protected override void OnDeactivate(EventArgs e)
{
_IsActive = false;
base.OnDeactivate(e);
}
[Browsable(false)]
public bool IsActive
{
get
{
return _IsActive;
}
}
}
/// <summary>
/// Defines the side of triangle pointer displayed on flyout popup.
/// </summary>
public enum ePointerSide
{
Top,
Bottom,
Left,
Right
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,837 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.ComponentModel.Design;
using System.Reflection;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(GroupPanel), "Controls.GroupPanel.ico"), ToolboxItem(true), Designer("DevComponents.DotNetBar.Design.GroupPanelDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class GroupPanel : PanelControl, INonClientControl
{
#region Private Variables
private NonClientPaintHandler m_NCPainter = null;
private Image m_TitleImage = null;
private eTitleImagePosition m_TitleImagePosition = eTitleImagePosition.Left;
private bool m_DrawTitleBox = true;
private bool m_IsShadowEnabled = false;
#endregion
#region Constructor
public GroupPanel()
{
m_NCPainter = new NonClientPaintHandler(this, eScrollBarSkin.Optimized);
m_NCPainter.BeforeBorderPaint += new CustomNCPaintEventHandler(NCBeforeBorderPaint);
m_NCPainter.AfterBorderPaint += new CustomNCPaintEventHandler(NCAfterBorderPaint);
this.SetStyle(ControlStyles.StandardDoubleClick, true);
}
#endregion
#region Internal Implementation
private ePanelColorTable _ColorTable = ePanelColorTable.Default;
/// <summary>
/// Gets or sets the panel color scheme.
/// </summary>
[DefaultValue(ePanelColorTable.Default), Category("Appearance"), Description("Indicates panel color scheme.")]
public ePanelColorTable ColorTable
{
get { return _ColorTable; }
set
{
_ColorTable = value;
SetColorTable(value);
}
}
protected override void OnResize(EventArgs e)
{
InvalidateNonClient();
base.OnResize(e);
}
/// <summary>
/// Gets or sets the image that appears in title with text.
/// </summary>
[Browsable(true), DefaultValue(null), Category("Visual"), Description("Indicates image that appears in title with text.")]
public Image TitleImage
{
get { return m_TitleImage; }
set
{
m_TitleImage = value;
RefreshTextClientRectangle();
this.Invalidate();
}
}
/// <summary>
/// Gets or sets the position of the title image. Default value is left.
/// </summary>
[Browsable(true), DefaultValue(eTitleImagePosition.Left), Category("Visual"), Description("Indicates position of the title image.")]
public eTitleImagePosition TitleImagePosition
{
get { return m_TitleImagePosition; }
set
{
m_TitleImagePosition = value;
RefreshTextClientRectangle();
this.Invalidate();
}
}
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
/// <summary>
/// Gets or sets the scrollbar skining type when control is using Office 2007 style.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public eScrollBarSkin ScrollbarSkin
{
get { return m_NCPainter.SkinScrollbars; }
set { m_NCPainter.SkinScrollbars = value; }
}
protected override void Dispose(bool disposing)
{
if (m_NCPainter != null)
{
m_NCPainter.Dispose();
//m_NCPainter = null;
}
if (BarUtilities.DisposeItemImages && !this.DesignMode)
{
BarUtilities.DisposeImage(ref m_TitleImage);
}
base.Dispose(disposing);
}
/// <summary>
/// Specifies whether item is drawn using Themes when running on OS that supports themes like Windows XP.
/// </summary>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(false), Category("Appearance"), Description("Specifies whether item is drawn using Themes when running on OS that supports themes like Windows XP.")]
public override bool ThemeAware
{
get
{
return base.ThemeAware;
}
set
{
base.ThemeAware = value;
}
}
/// <summary>
/// Gets or sets whether box around the title of the group is drawn. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("")]
public bool DrawTitleBox
{
get { return m_DrawTitleBox; }
set
{
if (m_DrawTitleBox != value)
{
m_DrawTitleBox = value;
this.InvalidateNonClient();
}
}
}
/// <summary>
/// Invalidates non-client area of the control.
/// </summary>
public void InvalidateNonClient()
{
if (!BarFunctions.IsHandleValid(this)) return;
const int RDW_INVALIDATE = 0x0001;
const int RDW_FRAME = 0x0400;
NativeFunctions.RECT r = new NativeFunctions.RECT(0, 0, this.Width, this.Height);
NativeFunctions.RedrawWindow(this.Handle, ref r, IntPtr.Zero, RDW_INVALIDATE | RDW_FRAME);
}
/// <summary>
/// Paints insides of the control.
/// </summary>
/// <param name="e">Paint event arguments.</param>
protected override void PaintInnerContent(PaintEventArgs e, ElementStyle style, bool paintText)
{
Graphics g = e.Graphics;
if (this.TextMarkupElement == null)
RefreshTextClientRectangle();
Rectangle r = this.DisplayRectangle;
#if FRAMEWORK20
r.X -= this.Padding.Left;
r.Y -= this.Padding.Top;
r.Width += this.Padding.Horizontal;
r.Height += this.Padding.Vertical;
#else
r.X -= this.DockPadding.Left;
r.Y -= this.DockPadding.Top;
r.Width += this.DockPadding.Left + this.DockPadding.Right;
r.Height += this.DockPadding.Top + this.DockPadding.Bottom;
#endif
r.Inflate(2, 2);
ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, r);
info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
ElementStyleDisplay.PaintBackground(info, false);
if (style.BackgroundImage != null) ElementStyleDisplay.PaintBackgroundImage(info);
if (!m_IsShadowEnabled) return;
ShadowPaintInfo pi = new ShadowPaintInfo();
pi.Graphics = g;
pi.Size = 6;
foreach (Control c in this.Controls)
{
if (!c.Visible || c.BackColor == Color.Transparent && !(c is GroupPanel)) continue;
if (c is GroupPanel)
{
GroupPanel p = c as GroupPanel;
pi.Rectangle = new Rectangle(c.Bounds.X, c.Bounds.Y + p.GetInternalClientRectangle().Y / 2, c.Bounds.Width, c.Bounds.Height - p.GetInternalClientRectangle().Y / 2);
}
else
pi.Rectangle = c.Bounds;
ShadowPainter.Paint2(pi);
}
}
private void NCAfterBorderPaint(object sender, CustomNCPaintEventArgs e)
{
Graphics g = e.Graphics;
TextRenderingHint th = g.TextRenderingHint;
SmoothingMode sm = g.SmoothingMode;
if (this.AntiAlias)
{
g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
g.SmoothingMode = SmoothingMode.AntiAlias;
}
g.ResetClip();
ElementStyle style = this.Style;
if (!this.Enabled)
{
style = style.Copy();
style.TextColor = GetColorScheme().ItemDisabledText;
}
if (m_DrawTitleBox && !m_TitleArea.IsEmpty)
{
DisplayHelp.FillRoundedRectangle(g, m_TitleArea, 2, style.BackColor, style.BackColor2, -90);
DisplayHelp.DrawRoundedRectangle(g, this.Style.BorderColor, m_TitleArea, 2);
}
Rectangle rText = new Rectangle(m_NCPainter.ClientRectangle.X + 4, 1, this.ClientRectangle.Width - 8, m_NCPainter.ClientRectangle.Y - 1);
if (m_TitleImage != null)
{
Size textSize = GetAutoSize(rText.Width);
if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes)
{
g.DrawImage(m_TitleImage, rText.X - 1, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
rText.X += m_TitleImage.Width;
rText.Width -= m_TitleImage.Width;
}
else if (m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No || m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes)
{
g.DrawImage(m_TitleImage, rText.Right - m_TitleImage.Width, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
rText.Width -= m_TitleImage.Width;
}
else if (m_TitleImagePosition == eTitleImagePosition.Center)
{
g.DrawImage(m_TitleImage, rText.X + (rText.Width - m_TitleImage.Width) / 2, rText.Y, m_TitleImage.Width, m_TitleImage.Height);
}
rText.Y = rText.Bottom - textSize.Height - 2;
}
// Paint text
if (this.TextMarkupElement == null)
{
ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, g, rText);
info.RightToLeft = (this.RightToLeft == RightToLeft.Yes);
ElementStyleDisplay.PaintText(info, this.Text, this.Font);
}
else
{
TextRenderingHint tr = g.TextRenderingHint;
if (this.AntiAlias)
g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, style.TextColor, (this.RightToLeft == RightToLeft.Yes), Rectangle.Empty, true);
Rectangle r = this.TextMarkupElement.Bounds;
if (style.TextAlignment == eStyleTextAlignment.Center)
this.TextMarkupElement.Bounds = new Rectangle(this.TextMarkupElement.Bounds.X + (rText.Width - this.TextMarkupElement.Bounds.Width) / 2, this.TextMarkupElement.Bounds.Y,
this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
else if(style.TextAlignment == eStyleTextAlignment.Far && this.RightToLeft == RightToLeft.No || this.RightToLeft == RightToLeft.Yes && style.TextAlignment== eStyleTextAlignment.Near)
this.TextMarkupElement.Bounds = new Rectangle(rText.Right - this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Y,
this.TextMarkupElement.Bounds.Width, this.TextMarkupElement.Bounds.Height);
this.TextMarkupElement.Render(d);
g.TextRenderingHint = tr;
this.TextMarkupElement.Bounds = r;
}
g.TextRenderingHint = th;
g.SmoothingMode = sm;
}
private Rectangle m_TitleArea = Rectangle.Empty;
private void NCBeforeBorderPaint(object sender, CustomNCPaintEventArgs e)
{
m_TitleArea = Rectangle.Empty;
// Exclude text area from border rendering
if (this.Text != null && this.Text.Length > 0)
{
Size s = GetAutoSize(this.ClientRectangle.Width - 8);
Rectangle r = new Rectangle(m_NCPainter.ClientRectangle.X + 3, 0, s.Width, m_NCPainter.ClientRectangle.Y);
Size availSize = new Size(m_NCPainter.ClientRectangle.Width - 8, m_NCPainter.ClientRectangle.Y);
if (m_TitleImage != null && (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes ||
m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No))
{
//r.X -= m_TitleImage.Width;
availSize.Width -= m_TitleImage.Width;
}
else if (m_TitleImage != null && (m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes ||
m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No))
{
r.X += m_TitleImage.Width;
availSize.Width -= m_TitleImage.Width;
}
//if (this.TextMarkupElement == null)
{
if (this.Style.TextAlignment == eStyleTextAlignment.Center)
{
//r.X = m_NCPainter.ClientRectangle.X;
r.X += (availSize.Width - r.Width) / 2;
}
else if (this.Style.TextAlignment == eStyleTextAlignment.Far || this.RightToLeft == RightToLeft.Yes && this.Style.TextAlignment == eStyleTextAlignment.Near)
{
r.X = r.X + (availSize.Width - r.Width);
}
}
if (!r.IsEmpty)
{
r.Inflate(3, 0);
r.Width += 3;
}
e.Graphics.SetClip(r, System.Drawing.Drawing2D.CombineMode.Exclude);
m_TitleArea = r;
}
if (m_TitleImage != null)
{
Rectangle r = new Rectangle(m_NCPainter.ClientRectangle.X + 3, 0, m_TitleImage.Width, m_TitleImage.Height);
if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes ||
m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No)
{
r.X = m_NCPainter.ClientRectangle.Right - r.Width - 4;
}
else if (m_TitleImagePosition == eTitleImagePosition.Center)
{
r.X = m_NCPainter.ClientRectangle.X;
r.X += (m_NCPainter.ClientRectangle.Width - r.Width) / 2;
}
e.Graphics.SetClip(r, System.Drawing.Drawing2D.CombineMode.Exclude);
if (m_TitleArea.IsEmpty)
m_TitleArea = r;
else
m_TitleArea = Rectangle.Union(r, m_TitleArea);
}
}
/// <summary>
/// Returns the size of the panel calculated based on the text assigned.
/// </summary>
/// <returns>Calculated size of the panel or Size.Empty if panel size cannot be calculated.</returns>
private Size GetAutoSize(int preferedWidth)
{
Size size = Size.Empty;
if (!this.IsHandleCreated) return size;
if (TextMarkupElement != null)
{
if (preferedWidth == 0)
{
size = TextMarkupElement.Bounds.Size;
}
else
{
size = GetMarkupSize(preferedWidth);
}
size.Width += 4;
//size.Height += 1;
}
else if (this.Text.Length > 0)
{
Font font = this.Font;
if (this.Style.Font != null) font = this.Style.Font;
eTextFormat tf = eTextFormat.Default | eTextFormat.SingleLine | eTextFormat.NoPrefix;
using (Graphics g = BarFunctions.CreateGraphics(this))
{
if (preferedWidth <= 0)
size = TextDrawing.MeasureString(g, this.Text, font, 0, tf);
else
size = TextDrawing.MeasureString(g, this.Text, font, preferedWidth, tf);
}
size.Width += 2;
size.Height += 2;
}
if (size.IsEmpty) return size;
size.Width += this.Style.MarginLeft + this.Style.MarginRight;
size.Height += this.Style.MarginTop + this.Style.MarginBottom;
return size;
}
private Size GetMarkupSize(int proposedWidth)
{
Size size = Size.Empty;
if (TextMarkupElement != null)
{
Rectangle r = new Rectangle(0, 0, proposedWidth, 500);
r.Inflate(-2, -2);
Graphics g = this.CreateGraphics();
TextMarkup.BodyElement markup = TextMarkup.MarkupParser.Parse(this.Text);
try
{
if (AntiAlias)
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.TextRenderingHint = DisplayHelp.AntiAliasTextRenderingHint;
}
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, this.Font, SystemColors.Control, (this.RightToLeft == RightToLeft.Yes));
markup.Measure(r.Size, d);
size = markup.Bounds.Size;
}
finally
{
g.Dispose();
}
}
return size;
}
protected override void RefreshTextClientRectangle()
{
if (m_NCPainter != null)
{
Rectangle r = new Rectangle(m_NCPainter.ClientRectangle.X, 0, m_NCPainter.ClientRectangle.Width, this.Height / 2);
r.Inflate(-2, 0);
if (m_TitleImage != null)
{
if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.No ||
m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.Yes)
{
r.X += m_TitleImage.Width;
r.Width -= m_TitleImage.Width;
}
else if (m_TitleImagePosition == eTitleImagePosition.Left && this.RightToLeft == RightToLeft.Yes ||
m_TitleImagePosition == eTitleImagePosition.Right && this.RightToLeft == RightToLeft.No)
{
r.Width -= m_TitleImage.Width;
}
Size s = GetMarkupSize(r.Width);
r.Y = Math.Max(0, m_NCPainter.ClientRectangle.Y - s.Height - 4);
}
this.ClientTextRectangle = r;
}
else
this.ClientTextRectangle = this.ClientRectangle;
ResizeMarkup();
}
/// <summary>
/// Gets or sets whether text rectangle painted on panel is considering docked controls inside the panel.
/// </summary>
[Browsable(false), DefaultValue(true), Category("Appearance"), Description("Indicates whether text rectangle painted on panel is considering docked controls inside the panel.")]
public override bool TextDockConstrained
{
get { return base.TextDockConstrained; }
set { base.TextDockConstrained = value; }
}
/// <summary>
/// Gets or sets whether panel automatically provides shadows for child controls. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Appearance"), Description("Indicates whether panel automatically provides shadows for child controls.")]
public bool IsShadowEnabled
{
get { return m_IsShadowEnabled; }
set
{
if (m_IsShadowEnabled != value)
{
m_IsShadowEnabled = value;
this.Invalidate();
}
}
}
/// <summary>
/// Applies color scheme to the panel.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetColorTable(ePanelColorTable colorScheme)
{
GroupPanel p = this;
DevComponents.DotNetBar.Rendering.ColorFactory factory = DevComponents.DotNetBar.Rendering.ColorFactory.Empty;
p.CanvasColor = SystemColors.Control;
p.ResetStyle();
p.ColorSchemeStyle = eDotNetBarStyle.Office2007;
if (colorScheme == ePanelColorTable.Default)
SetDefaultPanelStyle();
else if (colorScheme == ePanelColorTable.Green)
{
p.Style.BackColor2 = factory.GetColor(0x9CBF8B);
p.Style.BackColorGradientAngle = 90;
p.Style.BackColor = factory.GetColor(0xC3D9B9);
p.Style.Border = DevComponents.DotNetBar.eStyleBorderType.Solid;
p.Style.BorderWidth = 1;
p.Style.BorderColor = factory.GetColor(0x72A45A);
p.Style.CornerDiameter = 4;
p.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
p.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
p.Style.TextColor = factory.GetColor(0x3C4A1F);
p.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
}
else if (colorScheme == ePanelColorTable.Orange)
{
p.Style.BackColor = factory.GetColor(0xFAC08F);
p.Style.BackColor2 = factory.GetColor(0xF79646);
p.Style.BorderColor = factory.GetColor(0x974806);
p.Style.TextColor = factory.GetColor(0x7F3D06);
p.Style.BackColorGradientAngle = 90;
p.Style.Border = DevComponents.DotNetBar.eStyleBorderType.Solid;
p.Style.BorderWidth = 1;
p.Style.CornerDiameter = 4;
p.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
p.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
p.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
}
else if (colorScheme == ePanelColorTable.Red)
{
p.Style.BackColor = factory.GetColor(0xE5BFBF);
p.Style.BackColor2 = factory.GetColor(0xD39696);
p.Style.BorderColor = factory.GetColor(0x953734);
p.Style.TextColor = factory.GetColor(0x632423);
p.Style.BackColorGradientAngle = 90;
p.Style.Border = DevComponents.DotNetBar.eStyleBorderType.Solid;
p.Style.BorderWidth = 1;
p.Style.CornerDiameter = 4;
p.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
p.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
p.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
}
else if (colorScheme == ePanelColorTable.Yellow)
{
p.Style.BackColor = factory.GetColor(0xFFF3B2);
p.Style.BackColor2 = factory.GetColor(0xFAD945);
p.Style.BorderColor = factory.GetColor(0xEE9311);
p.Style.TextColor = factory.GetColor(0x3F3F00);
p.Style.BackColorGradientAngle = 90;
p.Style.Border = DevComponents.DotNetBar.eStyleBorderType.Solid;
p.Style.BorderWidth = 1;
p.Style.CornerDiameter = 4;
p.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
p.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
p.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
}
else if (colorScheme == ePanelColorTable.Magenta)
{
p.Style.BackColor = factory.GetColor(0xEF91B4);
p.Style.BackColor2 = factory.GetColor(0xE66896);
p.Style.BorderColor = factory.GetColor(0xB12753);
p.Style.TextColor = factory.GetColor(0x8E2648);
p.Style.BackColorGradientAngle = 90;
p.Style.Border = DevComponents.DotNetBar.eStyleBorderType.Solid;
p.Style.BorderWidth = 1;
p.Style.CornerDiameter = 4;
p.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
p.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
p.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
}
}
/// <summary>
/// Applies default group panel style to the control.
/// </summary>
public void SetDefaultPanelStyle()
{
GroupPanel p = this;
p.CanvasColor = SystemColors.Control;
p.ResetStyle();
p.ColorSchemeStyle = eDotNetBarStyle.Office2007;
p.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2;
p.Style.BackColorGradientAngle = 90;
p.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground;
p.Style.Border = DevComponents.DotNetBar.eStyleBorderType.Solid;
p.Style.BorderWidth = 1;
p.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder;
p.Style.CornerDiameter = 4;
p.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded;
p.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;
p.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText;
p.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near;
}
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, height, specified);
UpdateInternalClientSize(width, height, specified);
}
protected override void OnTextChanged(EventArgs e)
{
if (IsHandleCreated)
{
UpdateInternalClientSize(this.Width, this.Height, BoundsSpecified.Width | BoundsSpecified.Height);
InvalidateNonClient();
}
base.OnTextChanged(e);
}
private void UpdateInternalClientSize(int width, int height, BoundsSpecified specified)
{
if (((specified & BoundsSpecified.Height) == BoundsSpecified.Height || (specified & BoundsSpecified.Width) == BoundsSpecified.Width))
{
ElementStyle style = this.Style;
Rectangle r = new Rectangle(0, 0, width, height);
if (m_NCPainter != null)
{
Rectangle cr = m_NCPainter.GetClientRectangleForBorderStyle(r, style);
if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height)
height = cr.Height;
if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width)
width = cr.Width;
Type type = typeof(Control);
try // try with ignore catch is bad idea but in this case its for future proofing, just in case M$ removes these members
{
type.InvokeMember("clientWidth", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, this, new object[] { width });
type.InvokeMember("clientHeight", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, this, new object[] { height });
}
catch { }
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override bool AutoScroll
{
get
{
return base.AutoScroll;
}
set
{
base.AutoScroll = value;
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public override Point AutoScrollOffset
{
get
{
return base.AutoScrollOffset;
}
set
{
base.AutoScrollOffset = value;
}
}
#endregion
#region INonClientControl Members
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m_NCPainter == null)
{
base.WndProc(ref m);
return;
}
if (m.Msg == (int)WinApi.WindowsMessages.WM_HSCROLL || m.Msg == (int)WinApi.WindowsMessages.WM_VSCROLL ||
m.Msg == (int)WinApi.WindowsMessages.WM_MOUSEWHEEL)
{
//Region reg = new Region(new Rectangle(0, 0, this.Width, this.Height));
//SuspendPaint = true;
//try
//{
bool callBase = m_NCPainter.WndProc(ref m);
if (callBase)
BaseWndProc(ref m);
//}
//finally
//{
//SuspendPaint = false;
//}
//foreach (Control c in this.Controls)
//{
// if (c.Visible)
// reg.Exclude(c.Bounds);
//}
RefreshTextClientRectangle();
//this.Invalidate(reg, false);
//if (this.Controls.Count > 0)
// this.Update();
//reg.Dispose();
}
else
{
bool callBase = m_NCPainter.WndProc(ref m);
//if (m.Msg == (int)WinApi.WindowsMessages.WM_NCCALCSIZE)
// UpdateInternalClientSize(this.Width, this.Height, BoundsSpecified.Width | BoundsSpecified.Height);
if (callBase)
BaseWndProc(ref m);
}
}
void INonClientControl.BaseWndProc(ref Message m)
{
BaseWndProc(ref m);
}
/// <summary>
/// Returns the renderer control will be rendered with.
/// </summary>
/// <returns>The current renderer.</returns>
public virtual Rendering.BaseRenderer GetRenderer()
{
if (Rendering.GlobalManager.Renderer != null)
return Rendering.GlobalManager.Renderer;
return null;
}
ItemPaintArgs INonClientControl.GetItemPaintArgs(System.Drawing.Graphics g)
{
ItemPaintArgs pa = new ItemPaintArgs(this as IOwner, this, g, GetColorScheme());
pa.Renderer = this.GetRenderer();
pa.DesignerSelection = false; // m_DesignerSelection;
pa.GlassEnabled = !this.DesignMode && WinApi.IsGlassEnabled;
return pa;
}
ElementStyle INonClientControl.BorderStyle
{
get { return this.Style; }
}
void INonClientControl.PaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
}
IntPtr INonClientControl.Handle
{
get { return this.Handle; }
}
int INonClientControl.Width
{
get { return this.Width; }
}
int INonClientControl.Height
{
get { return this.Height; }
}
bool INonClientControl.IsHandleCreated
{
get { return this.IsHandleCreated; }
}
System.Drawing.Point INonClientControl.PointToScreen(System.Drawing.Point client)
{
return this.PointToScreen(client);
}
System.Drawing.Color INonClientControl.BackColor
{
get { return this.BackColor; }
}
void DevComponents.DotNetBar.Controls.INonClientControl.RenderNonClient(Graphics g) { }
void DevComponents.DotNetBar.Controls.INonClientControl.AdjustClientRectangle(ref Rectangle r)
{
Size textSize = GetAutoSize(r.Width);
if (m_TitleImage != null)
{
textSize.Height = Math.Max(m_TitleImage.Height, textSize.Height);
}
if (textSize.Height > r.Height) textSize.Height = r.Height - 8;
r.Y += textSize.Height;
r.Height -= textSize.Height;
}
void INonClientControl.AdjustBorderRectangle(ref Rectangle r)
{
if (this.Text != "")
{
int h = GetNonClientTopHeight();
r.Y += h;
r.Height -= h;
}
}
private int GetNonClientTopHeight()
{
Font f = this.Font;
if (this.Style.Font != null)
f = this.Style.Font;
int h = (int)(f.Height * .7f);
if (m_TitleImage != null)
{
h = Math.Max(m_TitleImage.Height - (f.Height - h - 1), h);
}
return h;
}
internal Rectangle GetInternalClientRectangle()
{
return m_NCPainter.ClientRectangle;
}
private Color _DisabledBackColor = Color.Empty;
/// <summary>
/// Specifies back color when Enabled=false
/// </summary>
[Browsable(false), Category("Appearance"), Description("Specifies back color when Enabled=false")]
public Color DisabledBackColor
{
get { return _DisabledBackColor; }
set
{
_DisabledBackColor = value;
if (!Enabled) this.Invalidate();
}
}
#endregion
}
/// <summary>
/// Defines predefined color schemes for panel control.
/// </summary>
public enum ePanelColorTable
{
Default,
Green,
Orange,
Red,
Yellow,
Magenta
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,696 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
namespace DevComponents.DotNetBar
{
#if FRAMEWORK20
[Designer("DevComponents.DotNetBar.Design.LabelXDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
#endif
[ToolboxBitmap(typeof(LabelX), "Controls.LabelX.ico"), ToolboxItem(true), System.Runtime.InteropServices.ComVisible(false)]
public class LabelX : BaseItemControl, ICommandSource
{
#region Private Variables
private LabelItem m_Label = null;
private bool m_UseMnemonic = true;
private Size m_PreferredSize = Size.Empty;
#endregion
#region Events
/// <summary>
/// Occurs when text markup link is clicked. Markup links can be created using "a" tag, for example:
/// <a name="MyLink">Markup link</a>
/// </summary>
public event MarkupLinkClickEventHandler MarkupLinkClick;
#endregion
#region Constructor, Dispose
public LabelX()
{
m_Label = new LabelItem();
m_Label.Style = eDotNetBarStyle.Office2007;
m_Label.MarkupLinkClick += new MarkupLinkClickEventHandler(LabelMarkupLinkClick);
this.FocusCuesEnabled = false;
this.HostItem = m_Label;
this.TabStop = false;
this.SetStyle(ControlStyles.Selectable, false);
}
#endregion
#region Internal Implementation
/// <summary>
/// Specifies spacing between label image and text.
/// </summary>
[DefaultValue(2), Category("Appearance"), Description("Specifies spacing between label image and text.")]
public int ImageTextSpacing
{
get { return m_Label.ImageTextSpacing; }
set { m_Label.ImageTextSpacing = value; }
}
[EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
protected string PlainText
{
get
{
return m_Label.PlainText;
}
}
/// <summary>
/// Gets or sets whether text-markup support is enabled for controls Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the control instead of it being parsed as text-markup.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether text-markup support is enabled for controls Text property.")]
public bool EnableMarkup
{
get { return m_Label.EnableMarkup; }
set
{
m_Label.EnableMarkup = value;
}
}
/// <summary>
/// Gets or sets whether control displays focus cues when focused.
/// </summary>
[DefaultValue(false), Category("Behavior"), Description("Indicates whether control displays focus cues when focused.")]
public override bool FocusCuesEnabled
{
get
{
return base.FocusCuesEnabled;
}
set
{
base.FocusCuesEnabled = value;
}
}
protected override void OnHandleCreated(EventArgs e)
{
#if FRAMEWORK20
if (this.AutoSize)
this.AdjustSize();
#endif
this.RecalcLayout();
base.OnHandleCreated(e);
}
/// <summary>
/// Recalculates the size of the internal item.
/// </summary>
protected override void RecalcSize()
{
m_Label.SuspendPaint = true;
m_Label.Width = Dpi.DescaleWidth(m_Label.Bounds.Width);
m_Label.Height = Dpi.DescaleHeight(m_Label.Bounds.Height);
m_Label.SuspendPaint = false;
base.RecalcSize();
}
protected override void OnBackColorChanged(EventArgs e)
{
m_Label.BackColor = this.BackColor;
base.OnBackColorChanged(e);
}
protected override void OnForeColorChanged(EventArgs e)
{
if (this.ForeColor == SystemColors.ControlText)
m_Label.ForeColor = Color.Empty;
else
m_Label.ForeColor = this.ForeColor;
base.OnForeColorChanged(e);
}
/// <summary>
/// Gets or sets the border sides that are displayed. Default value specifies border on all 4 sides.
/// </summary>
[Browsable(false), Category("Appearance"), DefaultValue(LabelItem.DEFAULT_BORDERSIDE), Description("Specifies border sides that are displayed.")]
public eBorderSide BorderSide
{
get { return m_Label.BorderSide; }
set { m_Label.BorderSide = value; InvalidateAutoSize(); }
}
/// <summary>
/// Gets or sets the type of the border drawn around the label.
/// </summary>
[Browsable(false), Category("Appearance"), DefaultValue(eBorderType.None), Description("Indicates the type of the border drawn around the label.")]
public eBorderType BorderType
{
get { return m_Label.BorderType; }
set { m_Label.BorderType = value; InvalidateAutoSize(); }
}
/// <summary>
/// Specifies label image.
/// </summary>
[Browsable(true), Category("Appearance"), Description("The image that will be displayed on the face of the item."), DefaultValue(null)]
public System.Drawing.Image Image
{
get { return m_Label.Image; }
set { m_Label.Image = value; InvalidateAutoSize(); }
}
/// <summary>
/// Gets/Sets the image position inside the label.
/// </summary>
[Browsable(true), Category("Appearance"), Description("The alignment of the image in relation to text displayed by this item."), DefaultValue(eImagePosition.Left)]
public eImagePosition ImagePosition
{
get { return m_Label.ImagePosition; }
set { m_Label.ImagePosition = value; InvalidateAutoSize(); }
}
/// <summary>
/// Gets or sets the border line color when border is single line.
/// </summary>
[Browsable(true), Category("Appearance"), Description("Indicates border line color when border is single line.")]
public Color SingleLineColor
{
get { return m_Label.SingleLineColor; }
set { m_Label.SingleLineColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSingleLineColor()
{
return m_Label.ShouldSerializeSingleLineColor();
}
/// <summary>
/// Resets the SingleLineColor property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSingleLineColor()
{
m_Label.ResetSingleLineColor();
}
/// <summary>
/// Gets or sets the text associated with this item.
/// </summary>
[Browsable(true), Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor)), Category("Appearance"), Description("The text contained in the item.")]
public override string Text
{
get { return base.Text; }
set { base.Text = value; }
}
/// <summary>
/// Gets or sets the horizontal text alignment.
/// </summary>
[Browsable(true), DefaultValue(StringAlignment.Near), DevCoBrowsable(true), Category("Layout"), Description("Indicates text alignment.")]
public System.Drawing.StringAlignment TextAlignment
{
get { return m_Label.TextAlignment; }
set
{
m_Label.TextAlignment = value;
this.RecalcLayout();
}
}
/// <summary>
/// Gets or sets the text vertical alignment.
/// </summary>
[Browsable(true), DefaultValue(System.Drawing.StringAlignment.Center), DevCoBrowsable(true), Category("Layout"), Description("Indicates text line alignment.")]
public System.Drawing.StringAlignment TextLineAlignment
{
get { return m_Label.TextLineAlignment; }
set
{
m_Label.TextLineAlignment = value;
this.RecalcLayout();
}
}
/// <summary>
/// Gets or sets a value that determines whether text is displayed in multiple lines or one long line.
/// </summary>
[Browsable(true), Category("Style"), DefaultValue(false), Description("Gets or sets a value that determines whether text is displayed in multiple lines or one long line.")]
public bool WordWrap
{
get { return m_Label.WordWrap; }
set { m_Label.WordWrap = value; RecalcLayout(); }
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new bool TabStop
{
get { return base.TabStop; }
set { base.TabStop = value; }
}
/// <summary>
/// Gets or sets the left padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout"), Description("Indicates left padding in pixels.")]
public int PaddingLeft
{
get { return m_Label.PaddingLeft; }
set { m_Label.PaddingLeft = value; InvalidateAutoSize(); }
}
/// <summary>
/// Gets or sets the right padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout"), Description("Indicates right padding in pixels.")]
public int PaddingRight
{
get
{
return m_Label.PaddingRight;
}
set
{
m_Label.PaddingRight = value;
InvalidateAutoSize();
}
}
/// <summary>
/// Gets or sets the top padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout"), Description("Indicates top padding in pixels.")]
public int PaddingTop
{
get
{
return m_Label.PaddingTop;
}
set
{
m_Label.PaddingTop = value;
InvalidateAutoSize();
}
}
/// <summary>
/// Gets or sets the bottom padding in pixels.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout"), Description("Indicates bottom padding in pixels.")]
public int PaddingBottom
{
get
{
return m_Label.PaddingBottom;
}
set
{
m_Label.PaddingBottom = value;
InvalidateAutoSize();
}
}
private void LabelMarkupLinkClick(object sender, MarkupLinkClickEventArgs e)
{
OnMarkupLinkClick(e);
}
/// <summary>
/// Invokes the MarkupLinkClick event.
/// </summary>
/// <param name="e">Provides additional data about event.</param>
protected virtual void OnMarkupLinkClick(MarkupLinkClickEventArgs e)
{
if (MarkupLinkClick != null)
MarkupLinkClick(this, e);
}
/// <summary>
/// Gets or sets a value indicating whether the control interprets an ampersand character (&) in the control's Text property to be an access key prefix character.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether the control interprets an ampersand character (&) in the control's Text property to be an access key prefix character.")]
public bool UseMnemonic
{
get { return m_UseMnemonic; }
set
{
m_UseMnemonic = value;
InvalidateAutoSize();
this.Invalidate();
}
}
protected void InvalidateAutoSize()
{
m_PreferredSize = Size.Empty;
}
protected override void OnPaint(PaintEventArgs e)
{
if (m_UseMnemonic)
m_Label.ShowPrefix = true;
else
m_Label.ShowPrefix = false;
if (m_Label.NeedRecalcSize) m_Label.RecalcSize();
base.OnPaint(e);
}
private bool CanProcessMnemonic()
{
if (!this.Enabled || !this.Visible)
return false;
return true;
}
[UIPermission(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
protected override bool ProcessMnemonic(char charCode)
{
if ((!this.UseMnemonic || !Control.IsMnemonic(charCode, this.Text)) || !this.CanProcessMnemonic() || Control.ModifierKeys != Keys.Alt || m_Label.IsUsingTextMarkup)
{
return false;
}
Control parent = this.Parent;
if (parent != null)
{
if (parent.SelectNextControl(this, true, false, true, false) && !parent.ContainsFocus)
{
parent.Focus();
}
}
return true;
}
#if FRAMEWORK20
[Localizable(true), Browsable(false)]
public new System.Windows.Forms.Padding Padding
{
get { return base.Padding; }
set { base.Padding = value; }
}
internal bool IsUsingTextMarkup
{
get
{
if (m_Label != null)
return m_Label.TextMarkupBody != null;
return false;
}
}
public override Size GetPreferredSize(Size proposedSize)
{
if (!m_PreferredSize.IsEmpty && (proposedSize.Width == m_PreferredSize.Width || proposedSize.Width == 0 || this.AutoSize)) return m_PreferredSize;
if (!BarFunctions.IsHandleValid(this) || this.DesignMode && !this.AutoSize)
return base.GetPreferredSize(proposedSize);
if (this.Text.Length == 0)
return base.GetPreferredSize(proposedSize);
int oldWidth = m_Label.Width, oldHeight = m_Label.Height;
m_Label.SuspendPaint = true;
m_Label.Width = 0;
m_Label.Height = 0;
if ((proposedSize.Width > 0 && proposedSize.Width < 500000 || this.MaximumSize.Width > 0) && m_Label.TextMarkupBody != null)
{
if (TextOrientation == eOrientation.Horizontal)
m_Label.RecalcSizeMarkup((this.MaximumSize.Width > 0 ? this.MaximumSize.Width : proposedSize.Width));
else
m_Label.RecalcSizeMarkup((this.MaximumSize.Height > 0 ? this.MaximumSize.Height : proposedSize.Height));
}
else
{
m_Label.RecalcSize();
if (this.WordWrap && m_Label.WidthInternal > this.MaximumSize.Width && this.MaximumSize.Width > 0)
{
m_Label.Height = 0;
m_Label.Width = Dpi.DescaleWidth(this.MaximumSize.Width);
m_Label.RecalcSize();
}
else if (this.WordWrap && m_Label.WidthInternal > proposedSize.Width && proposedSize.Width > 0)
{
m_Label.Height = 0;
m_Label.Width = Dpi.DescaleWidth(proposedSize.Width);
m_Label.RecalcSize();
}
}
Size s = m_Label.Size;
s.Height += 2;
if (this.TextOrientation == eOrientation.Vertical)
{
s.Width += Dpi.Width2;
}
if (this.Font.Size > 13)
s.Height += 2;
m_Label.Width = oldWidth;
m_Label.Height = oldHeight;
m_Label.SuspendPaint = false;
m_PreferredSize = s;
return m_PreferredSize;
}
/// <summary>
/// Gets or sets a value indicating whether the control is automatically resized to display its entire contents. You can set MaximumSize.Width property to set the maximum width used by the control.
/// </summary>
[Browsable(true), DefaultValue(false), EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
if (this.AutoSize != value)
{
base.AutoSize = value;
AdjustSize();
}
}
}
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
if (this.AutoSize)
{
Size preferredSize = Size.Empty;
if (width != m_PreferredSize.Width && width > 0)
{
InvalidateAutoSize();
preferredSize = this.GetPreferredSize(new Size(width, 0));
}
else
preferredSize = this.PreferredSize;
width = preferredSize.Width;
height = preferredSize.Height;
}
base.SetBoundsCore(x, y, width, height, specified);
}
private void AdjustSize()
{
if (this.AutoSize)
{
this.Size = base.PreferredSize;
}
}
protected override void OnFontChanged(EventArgs e)
{
InvalidateAutoSize();
base.OnFontChanged(e);
}
protected override void OnTextChanged(EventArgs e)
{
InvalidateAutoSize();
base.OnTextChanged(e);
this.AdjustSize();
}
#endif
/// <summary>
/// Gets or sets text-orientation. Default is horizontal.
/// </summary>
[DefaultValue(eOrientation.Horizontal), Category("Appearance"), Description("Indicates text-orientation")]
public eOrientation TextOrientation
{
get { return m_Label.TextOrientation; }
set
{
m_Label.TextOrientation = value;
InvalidateAutoSize();
this.AdjustSize();
}
}
/// <summary>
/// Gets or sets how vertical text is rotated when TextOrientation = Vertical.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates how vertical text is rotated when TextOrientation = Vertical.")]
public bool VerticalTextTopUp
{
get { return m_Label.VerticalTextTopUp; }
set
{
m_Label.VerticalTextTopUp = value;
if (TextOrientation == eOrientation.Vertical)
{
this.Invalidate();
}
}
}
/// <summary>
/// Gets the underlying LabelItem
/// </summary>
internal LabelItem LabelItem
{
get { return (m_Label); }
}
/// <summary>
/// Indicates the symbol displayed on label instead of the image. Setting the symbol overrides the image setting.
/// </summary>
[DefaultValue(""), Category("Appearance"), Description("Indicates the symbol displayed on face of the tile instead of the image. Setting the symbol overrides the image setting.")]
[Editor("DevComponents.DotNetBar.Design.SymbolTypeEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
public string Symbol
{
get { return m_Label.Symbol; }
set { m_Label.Symbol = value; }
}
/// <summary>
/// Gets or sets the symbol set used to represent the Symbol.
/// </summary>
[Browsable(false), DefaultValue(eSymbolSet.Awesome)]
public eSymbolSet SymbolSet
{
get { return m_Label.SymbolSet; }
set { m_Label.SymbolSet = value; }
}
/// <summary>
/// Indicates the size of the symbol in points.
/// </summary>
[DefaultValue(0f), Category("Appearance"), Description("Indicates the size of the symbol in points.")]
public float SymbolSize
{
get { return m_Label.SymbolSize; }
set { m_Label.SymbolSize = value; }
}
/// <summary>
/// Gets or sets the color of the symbol.
/// </summary>
[Category("Appearance"), Description("Indicates color of the symbol.")]
public Color SymbolColor
{
get { return m_Label.SymbolColor; }
set { m_Label.SymbolColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSymbolColor()
{
return m_Label.ShouldSerializeSymbolColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSymbolColor()
{
m_Label.ResetSymbolColor();
}
/// <summary>
/// Indicates whether label text is rendered using bold font unless the Font property is specifically set to different font.
/// </summary>
[DefaultValue(false), Category("Appearance"), Description("Indicates whether label text is rendered using bold font unless the Font property is specifically set to different font.")]
public bool FontBold
{
get { return m_Label.FontBold; }
set
{
if (m_Label.FontBold != value)
{
m_Label.FontBold = value;
this.Invalidate();
}
}
}
#endregion
#region ICommandSource Members
protected virtual void ExecuteCommand()
{
if (_Command == null) return;
CommandManager.ExecuteCommand(this);
}
/// <summary>
/// Gets or sets the command assigned to the item. Default value is null.
/// <remarks>Note that if this property is set to null Enabled property will be set to false automatically to disable the item.</remarks>
/// </summary>
[DefaultValue(null), Category("Commands"), Description("Indicates the command assigned to the item.")]
public Command Command
{
get { return (Command)((ICommandSource)this).Command; }
set
{
((ICommandSource)this).Command = value;
}
}
private ICommand _Command = null;
//[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
ICommand ICommandSource.Command
{
get
{
return _Command;
}
set
{
bool changed = false;
if (_Command != value)
changed = true;
if (_Command != null)
CommandManager.UnRegisterCommandSource(this, _Command);
_Command = value;
if (value != null)
CommandManager.RegisterCommand(this, value);
if (changed)
OnCommandChanged();
}
}
/// <summary>
/// Called when Command property value changes.
/// </summary>
protected virtual void OnCommandChanged()
{
}
private object _CommandParameter = null;
/// <summary>
/// Gets or sets user defined data value that can be passed to the command when it is executed.
/// </summary>
[Browsable(true), DefaultValue(null), Category("Commands"), Description("Indicates user defined data value that can be passed to the command when it is executed."), System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter)), System.ComponentModel.Localizable(true)]
public object CommandParameter
{
get
{
return _CommandParameter;
}
set
{
_CommandParameter = value;
}
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,489 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// A single horizontal or vertical line control.
/// </summary>
[ToolboxBitmap(typeof(Line), "Controls.Line.ico"), ToolboxItem(true), Description("Horizontal or Vertical Line Control")]
public class Line : Control
{
#region Constructor
/// <summary>
/// Initializes a new instance of the Line class.
/// </summary>
public Line()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.UserPaint
| ControlStyles.SupportsTransparentBackColor
, true);
}
#endregion
#region Implementation
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.None;
using (Pen pen = new Pen(ForeColor, _Thickness))
{
pen.DashStyle = _DashStyle;
pen.DashOffset = _DashOffset;
Point lineStart = LineStartPoint;
Point lineEnd = LineEndPoint;
if (_StartLineCap != eLineEndType.None && _Thickness > 1)
{
if (_VerticalLine)
lineStart.Y += _StartLineCapSize.Height / 2;
else
lineStart.X += _StartLineCapSize.Width / 2;
}
if (_EndLineCap != eLineEndType.None && _Thickness > 1)
{
if (_VerticalLine)
lineEnd.Y -= _EndLineCapSize.Height / 2;
else
lineEnd.X -= _EndLineCapSize.Width / 2;
}
g.DrawLine(pen, lineStart, lineEnd);
}
if (_StartLineCap != eLineEndType.None && _StartLineCapSize.Width > 0 && _StartLineCapSize.Height > 0)
DrawLineCap(g, LineStartPoint, _StartLineCap, _StartLineCapSize, true);
if (_EndLineCap != eLineEndType.None && _EndLineCapSize.Width > 0 && _EndLineCapSize.Height > 0)
DrawLineCap(g, LineEndPoint, _EndLineCap, _EndLineCapSize, false);
g.SmoothingMode = sm;
base.OnPaint(e);
}
private void DrawLineCap(Graphics g, Point linePoint, eLineEndType lineCap, Size capSize, bool isStartCap)
{
if (lineCap == eLineEndType.Arrow)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.HighQuality;
using (GraphicsPath path = new GraphicsPath())
{
if (isStartCap)
{
if (VerticalLine)
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X - capSize.Width/2, linePoint.Y+capSize.Height),
new Point(linePoint.X+capSize.Width / 2, linePoint.Y+capSize.Height)});
else
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X + capSize.Width, linePoint.Y-capSize.Height/2),
new Point(linePoint.X+capSize.Width, linePoint.Y+ capSize.Height/2)});
}
else
{
if (VerticalLine)
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X + capSize.Width / 2, linePoint.Y - capSize.Height),
new Point(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height)});
else
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X - capSize.Width, linePoint.Y + capSize.Height / 2),
new Point(linePoint.X - capSize.Width, linePoint.Y - capSize.Height/2)});
}
path.CloseAllFigures();
using (SolidBrush brush = new SolidBrush(ForeColor))
g.FillPath(brush, path);
}
g.SmoothingMode = sm;
}
else if (lineCap == eLineEndType.Circle)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.HighQuality;
using (SolidBrush brush = new SolidBrush(ForeColor))
{
if (VerticalLine && isStartCap)
g.FillEllipse(brush, new Rectangle(linePoint.X - capSize.Width/2, linePoint.Y , capSize.Width, capSize.Height));
else if (VerticalLine)
g.FillEllipse(brush, new Rectangle(linePoint.X - capSize.Width/2, linePoint.Y - capSize.Height - 1, capSize.Width, capSize.Height));
else if (isStartCap)
g.FillEllipse(brush, new Rectangle(linePoint.X, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height));
else
g.FillEllipse(brush, new Rectangle(linePoint.X - capSize.Width - 1, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height));
}
g.SmoothingMode = sm;
}
else if (lineCap == eLineEndType.Diamond)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.HighQuality;
using (GraphicsPath path = new GraphicsPath())
{
if (isStartCap)
{
if (VerticalLine)
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X - capSize.Width/2, linePoint.Y+capSize.Height / 2),
new Point(linePoint.X, linePoint.Y+capSize.Height),
new Point(linePoint.X+capSize.Width / 2, linePoint.Y+capSize.Height / 2)});
else
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X + capSize.Width/2, linePoint.Y-capSize.Height/2),
new Point(linePoint.X + capSize.Width, linePoint.Y),
new Point(linePoint.X+capSize.Width / 2, linePoint.Y+ capSize.Height/2)});
}
else
{
if (VerticalLine)
{
linePoint.Y--;
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X + capSize.Width / 2, linePoint.Y - capSize.Height / 2),
new Point(linePoint.X, linePoint.Y - capSize.Height),
new Point(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height / 2)});
}
else
{
linePoint.X--;
path.AddLines(new Point[] {
new Point(linePoint.X, linePoint.Y),
new Point(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height / 2),
new Point(linePoint.X - capSize.Width, linePoint.Y),
new Point(linePoint.X - capSize.Width / 2, linePoint.Y + capSize.Height/2)});
}
}
path.CloseAllFigures();
using (SolidBrush brush = new SolidBrush(ForeColor))
g.FillPath(brush, path);
}
g.SmoothingMode = sm;
}
else if (lineCap == eLineEndType.Rectangle)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.HighQuality;
using (SolidBrush brush = new SolidBrush(ForeColor))
{
if (VerticalLine && isStartCap)
g.FillRectangle(brush, new Rectangle(linePoint.X - capSize.Width / 2, linePoint.Y, capSize.Width, capSize.Height));
else if (VerticalLine)
g.FillRectangle(brush, new Rectangle(linePoint.X - capSize.Width / 2, linePoint.Y - capSize.Height - 1, capSize.Width, capSize.Height));
else if (isStartCap)
g.FillRectangle(brush, new Rectangle(linePoint.X, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height));
else
g.FillRectangle(brush, new Rectangle(linePoint.X - capSize.Width - 1, linePoint.Y - capSize.Height / 2, capSize.Width, capSize.Height));
}
g.SmoothingMode = sm;
}
}
private Point LineStartPoint
{
get
{
if (!_VerticalLine)
{
if (_LineAlignment == eItemAlignment.Center)
return new Point(0, this.Height / 2);
else if (_LineAlignment == eItemAlignment.Near)
return new Point(0, _Thickness / 2 + ((_StartLineCap != eLineEndType.None) ? _StartLineCapSize.Height / 2 : 0));
else if (_LineAlignment == eItemAlignment.Far)
return new Point(0, this.Height - _Thickness / 2 - ((_StartLineCap != eLineEndType.None) ? _StartLineCapSize.Height / 2 : 0));
}
else
{
if (_LineAlignment == eItemAlignment.Center)
return new Point(this.Width / 2, 0);
else if (_LineAlignment == eItemAlignment.Near)
{
return new Point(_Thickness / 2 + ((_EndLineCap != eLineEndType.None) ? _EndLineCapSize.Width / 2 : 0), 0);
}
else if (_LineAlignment == eItemAlignment.Far)
return new Point(this.Width - _Thickness / 2 - ((_EndLineCap != eLineEndType.None) ? _EndLineCapSize.Width / 2 : 0), 0);
}
return Point.Empty;
}
}
private Point LineEndPoint
{
get
{
if (!_VerticalLine)
{
return new Point(this.Width, LineStartPoint.Y);
}
else
{
return new Point(LineStartPoint.X, this.Height);
}
}
}
private eItemAlignment _LineAlignment = eItemAlignment.Center;
/// <summary>
/// Specifies the line alignment within control bounds.
/// </summary>
[DefaultValue(eItemAlignment.Center), Category("Appearance"), Description("Specifies the line alignment within control bounds.")]
public eItemAlignment LineAlignment
{
get { return _LineAlignment; }
set { _LineAlignment = value; this.Invalidate(); }
}
private float _DashOffset;
/// <summary>
/// Specifies distance from the start of a line to the beginning of a dash pattern.
/// </summary>
[DefaultValue(0f), Category("Appearance"), Description("Specifies distance from the start of a line to the beginning of a dash pattern.")]
public float DashOffset
{
get { return _DashOffset; }
set { _DashOffset = value; this.Invalidate(); }
}
private DashStyle _DashStyle = DashStyle.Solid;
/// <summary>
/// Specifies the line dash style.
/// </summary>
[DefaultValue(DashStyle.Solid), Category("Appearance"), Description("Specifies the line dash style.")]
public DashStyle DashStyle
{
get { return _DashStyle; }
set { _DashStyle = value; this.Invalidate(); }
}
//private LineCap _LineCap = System.Drawing.Drawing2D.LineCap.Round;
///// <summary>
///// Gets or sets the line cap i.e. line ending.
///// </summary>
//[DefaultValue(LineCap.Round), Category("Appearance"), Description("Specifies line cap i.e. line ending.")]
//public LineCap LineCap
//{
// get { return _LineCap; }
// set { _LineCap = value; this.Invalidate(); }
//}
private int _Thickness = 1;
/// <summary>
/// Gets or sets the line thickness in pixels.
/// </summary>
[DefaultValue(1), Category("Appearance"), Description("Indicates line thickness in pixels.")]
public int Thickness
{
get { return _Thickness; }
set
{
_Thickness = value;
this.Invalidate();
if (this.AutoSize) AdjustSize();
}
}
private bool _VerticalLine = false;
/// <summary>
/// Gets or sets whether vertical line is drawn. Default value is false which means horizontal line is drawn.
/// </summary>
[DefaultValue(false), Category("Appearance"), Description("Indicates whether vertical line is drawn.")]
public bool VerticalLine
{
get { return _VerticalLine; }
set
{
_VerticalLine = value;
this.Invalidate();
}
}
/// <summary>
/// Gets or sets a value indicating whether the control is automatically resized to display its entire contents. You can set MaximumSize.Width property to set the maximum width used by the control.
/// </summary>
[Browsable(true), DefaultValue(false), EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
if (this.AutoSize != value)
{
base.AutoSize = value;
AdjustSize();
}
}
}
private void AdjustSize()
{
this.Size = GetPreferredSize(this.Size);
}
public override Size GetPreferredSize(Size proposedSize)
{
if (this.VerticalLine)
return new Size(_Thickness, this.Height);
else
return new Size(this.Width, _Thickness);
//return base.GetPreferredSize(proposedSize);
}
private eLineEndType _StartLineCap = eLineEndType.None;
/// <summary>
/// Indicates the start of the line cap.
/// </summary>
[DefaultValue(eLineEndType.None), Category("Appearance"), Description("Indicates the start of the line cap.")]
public eLineEndType StartLineCap
{
get { return _StartLineCap; }
set
{
if (value != _StartLineCap)
{
eLineEndType oldValue = _StartLineCap;
_StartLineCap = value;
OnStartLineCapChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when StartLineCap property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnStartLineCapChanged(eLineEndType oldValue, eLineEndType newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("StartLineCap"));
this.Refresh();
}
private static readonly Size DefaultCapSize = new Size(6, 6);
private Size _StartLineCapSize = DefaultCapSize;
/// <summary>
/// Indicates the size of the start cap.
/// </summary>
[Category("Appearance"), Description("Indicates the size of the start cap.")]
public Size StartLineCapSize
{
get { return _StartLineCapSize; }
set
{
if (value != _StartLineCapSize)
{
Size oldValue = _StartLineCapSize;
_StartLineCapSize = value;
OnStartLineCapSizeChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when StartLineCapSize property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnStartLineCapSizeChanged(Size oldValue, Size newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("StartLineCapSize"));
this.Refresh();
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeStartLineCapSize()
{
return _StartLineCapSize != DefaultCapSize;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetStartLineCapSize()
{
this.StartLineCapSize = DefaultCapSize;
}
private eLineEndType _EndLineCap = eLineEndType.None;
/// <summary>
/// Indicates the start of the line cap.
/// </summary>
[DefaultValue(eLineEndType.None), Category("Appearance"), Description("Indicates the start of the line cap.")]
public eLineEndType EndLineCap
{
get { return _EndLineCap; }
set
{
if (value != _EndLineCap)
{
eLineEndType oldValue = _EndLineCap;
_EndLineCap = value;
OnEndLineCapChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when EndLineCap property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnEndLineCapChanged(eLineEndType oldValue, eLineEndType newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("EndLineCap"));
this.Refresh();
}
private Size _EndLineCapSize = DefaultCapSize;
/// <summary>
/// Indicates end line cap size.
/// </summary>
[Category("Appearance"), Description("Indicates end line cap size.")]
public Size EndLineCapSize
{
get { return _EndLineCapSize; }
set { _EndLineCapSize = value; this.Refresh(); }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeEndLineCapSize()
{
return _EndLineCapSize != DefaultCapSize;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetEndLineCapSize()
{
this.EndLineCapSize = DefaultCapSize;
}
#endregion
}
/// <summary>
/// Defined line end types.
/// </summary>
public enum eLineEndType
{
None,
Arrow,
Rectangle,
Circle,
Diamond
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for CheckStateConvert event.
/// </summary>
public class CheckStateConvertEventArgs : EventArgs
{
public readonly object Value;
public CheckState? CheckState = null;
/// <summary>
/// Initializes a new instance of the CheckStateConvertEventArgs class.
/// </summary>
/// <param name="value"></param>
public CheckStateConvertEventArgs(object value)
{
Value = value;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar
{
public class ListBoxAdvItemCheckEventArgs : EventArgs
{
/// <summary>
/// Indicates that CheckState change of the item should be canceled.
/// </summary>
public bool Cancel = false;
/// <summary>
/// Specifies the ListBoxItem that was changing.
/// </summary>
public readonly ListBoxItem Item;
/// <summary>
/// When data-bound provides the object which was used to generate an ListBoxItem.
/// </summary>
public readonly object Value;
/// <summary>
/// Initializes a new instance of the ListBoxAdvItemCheckEventArgs class.
/// </summary>
/// <param name="item"></param>
/// <param name="value"></param>
public ListBoxAdvItemCheckEventArgs(ListBoxItem item, object value)
{
Item = item;
Value = value;
}
}
}

View File

@@ -0,0 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar
{
public delegate void ListBoxAdvItemCheckEventHandler(object sender, ListBoxAdvItemCheckEventArgs e);
}

View File

@@ -0,0 +1,727 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the ListBoxAdv item for internal use. Not for public usage.
/// </summary>
public class ListBoxItem : BaseItem
{
#region Constructor
#endregion
#region Implementation
/// <summary>
/// Returns copy of the item.
/// </summary>
public override BaseItem Copy()
{
ListBoxItem copy = new ListBoxItem();
this.CopyToItem(copy);
return copy;
}
/// <summary>
/// Copies the ListBoxItem specific properties to new instance of the item.
/// </summary>
/// <param name="copy">New ListBoxItem instance.</param>
internal void InternalCopyToItem(ListBoxItem copy)
{
CopyToItem(copy);
}
/// <summary>
/// Copies the ListBoxItem specific properties to new instance of the item.
/// </summary>
/// <param name="copy">New item instance.</param>
protected override void CopyToItem(BaseItem copy)
{
base.CopyToItem(copy);
ListBoxItem item = copy as ListBoxItem;
item.IsSelected = _IsSelected;
item.Symbol = _Symbol;
item.SymbolSet = _SymbolSet;
item.SymbolColor = _SymbolColor;
item.SymbolSize = _SymbolSize;
}
public override void Paint(ItemPaintArgs p)
{
Rendering.BaseRenderer renderer = p.Renderer;
if (renderer != null)
{
ListBoxItemRendererEventArgs e = new ListBoxItemRendererEventArgs(this, p.Graphics);
e.ItemPaintArgs = p;
renderer.DrawListBoxItem(e);
}
else
{
Rendering.ListBoxItemPainter painter = PainterFactory.CreateListBoxItemPainter(this);
if (painter != null)
{
ListBoxItemRendererEventArgs e = new ListBoxItemRendererEventArgs(this, p.Graphics);
e.ItemPaintArgs = p;
painter.Paint(e);
}
}
if (this.DesignMode && this.Focused)
{
Rectangle r = m_Rect;
r.Inflate(-1, -1);
DesignTime.DrawDesignTimeSelection(p.Graphics, r, p.Colors.ItemDesignTimeBorder);
}
else if (this.Focused)
{
Rectangle r = m_Rect;
r.Inflate(-1, -1);
Color c = SystemColors.Control;
if (renderer is Rendering.Office2007Renderer) c = ((Rendering.Office2007Renderer)renderer).ColorTable.ListBoxItem.Default.TextColor;
using (Pen pen = new Pen(c, 1))
{
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
System.Drawing.Drawing2D.SmoothingMode sm = p.Graphics.SmoothingMode;
p.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
p.Graphics.DrawRectangle(pen, r);
p.Graphics.SmoothingMode = sm;
}
}
this.DrawInsertMarker(p.Graphics);
}
private CheckState _CheckState = CheckState.Unchecked;
private bool _HotTracking;
private Size _CheckBoxSize = new Size(13, 13);
private const int DefaultPadding = 2;
private Padding _Padding = new Padding(DefaultPadding);
internal const int ImageTextSpacing = 4;
internal const int CheckBoxTextSpacing = 6;
public override void RecalcSize()
{
ListBoxAdv cont = this.ContainerControl as ListBoxAdv;
if (cont == null || cont.Disposing || cont.IsDisposed) return;
bool checkBox = cont.CheckBoxesVisible;
int itemHeight = Dpi.Height(cont.ItemHeight);
Size size = Size.Empty;
Graphics g = BarFunctions.CreateGraphics(cont);
if (g == null) return;
try
{
if (!string.IsNullOrEmpty(_Symbol))
{
_ActualSymbolSize = GetSymbolSize(g);
size = _ActualSymbolSize;
}
else if (_Image != null)
{
size = Dpi.ImageSize(_Image.Size);
}
if (!string.IsNullOrEmpty(this.Text))
{
Size textSize = ButtonItemLayout.MeasureItemText(this, g, 0, cont.Font, eTextFormat.Default, cont.RightToLeft == RightToLeft.Yes);
size.Width += textSize.Width;
size.Height = Math.Max(size.Height, textSize.Height);
if (_Image != null || !string.IsNullOrEmpty(_Symbol))
size.Width += Dpi.Width(ImageTextSpacing);
}
else if (string.IsNullOrEmpty(_Symbol) && _Image == null)
size = new System.Drawing.Size(Dpi.Width16, Dpi.Height16);
size.Width += _Padding.Horizontal;
size.Height += _Padding.Vertical;
base.RecalcSize();
}
finally
{
g.Dispose();
}
if (checkBox)
{
size.Width += Dpi.Width(_CheckBoxSize.Width + CheckBoxTextSpacing);
size.Height = Math.Max(Dpi.Height(_CheckBoxSize.Height), size.Height);
}
if (itemHeight > 0) size.Height = itemHeight;
_CheckBoxBounds = Rectangle.Empty;
m_Rect.Size = size;
base.RecalcSize();
}
private Rectangle _CheckBoxBounds = Rectangle.Empty;
internal Rectangle CheckBoxBounds
{
get
{
return _CheckBoxBounds;
}
set
{
_CheckBoxBounds = value;
}
}
public override void InternalMouseEnter()
{
base.InternalMouseEnter();
if (!this.DesignMode)
{
_MouseOver = true;
if (this.GetEnabled() && _HotTracking)
this.Refresh();
}
}
public override void InternalMouseLeave()
{
base.InternalMouseLeave();
if (!this.DesignMode)
{
_MouseOver = false;
CheckBoxMouseState = eMouseState.None;
if (this.GetEnabled() && _HotTracking)
this.Refresh();
}
}
public override void InternalMouseMove(MouseEventArgs objArg)
{
if (_CheckBoxBounds.Contains(objArg.Location))
CheckBoxMouseState = eMouseState.Hot;
else
CheckBoxMouseState = eMouseState.None;
base.InternalMouseMove(objArg);
}
public override void InternalMouseDown(MouseEventArgs objArg)
{
if (objArg.Button == MouseButtons.Left && !_CheckBoxBounds.IsEmpty && _CheckBoxBounds.Contains(objArg.Location))
CheckBoxMouseState = eMouseState.Down;
base.InternalMouseDown(objArg);
}
public override void InternalMouseUp(MouseEventArgs objArg)
{
if (objArg.Button == MouseButtons.Left && !_CheckBoxBounds.IsEmpty && _CheckBoxBounds.Contains(objArg.Location))
{
this.CheckState = this.CheckState == System.Windows.Forms.CheckState.Checked ? System.Windows.Forms.CheckState.Unchecked : System.Windows.Forms.CheckState.Checked;
CheckBoxMouseState = eMouseState.Hot;
}
else if (objArg.Button == MouseButtons.Left)
{
if (this.Bounds.Contains(objArg.Location))
{
ListBoxAdv listBox = this.ContainerControl as ListBoxAdv;
if (listBox != null)
{
if (listBox.SelectionMode != eSelectionMode.None)
{
if (listBox.SelectionMode == eSelectionMode.MultiSimple)
this.SetIsSelected(!this.IsSelected, eEventSource.Mouse);
else if (listBox.SelectionMode == eSelectionMode.MultiExtended)
{
if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
{
this.SetIsSelected(!this.IsSelected, eEventSource.Mouse);
}
else if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
BaseItem itemContainer = listBox.GetBaseItemContainer();
int index = itemContainer.SubItems.IndexOf(this);
int hiSel = -1, lowSel = -1;
for (int i = 0; i < listBox.SelectedItems.Count; i++)
{
int itemIndex = itemContainer.SubItems.IndexOf(listBox.SelectedItems[i]);
if (itemIndex > hiSel || hiSel < 0) hiSel = itemIndex;
if (itemIndex < lowSel || lowSel < 0) lowSel = itemIndex;
}
if (hiSel < 0 || lowSel < 0)
this.SetIsSelected(true, eEventSource.Mouse);
else
{
if (index < lowSel)
{
for (int i = lowSel; i >= index; i--)
{
ListBoxItem listItem = itemContainer.SubItems[i] as ListBoxItem;
if (listItem != null) listItem.SetIsSelected(true, eEventSource.Mouse);
}
}
else if (index > hiSel)
{
for (int i = hiSel; i <= index; i++)
{
ListBoxItem listItem = itemContainer.SubItems[i] as ListBoxItem;
if (listItem != null) listItem.SetIsSelected(true, eEventSource.Mouse);
}
}
}
}
else
{
listBox.ClearSelectedItems(eEventSource.Mouse);
this.SetIsSelected(true, eEventSource.Mouse);
}
}
else if(!this.IsSelected)
this.SetIsSelected(true, eEventSource.Mouse);
}
}
else
this.SetIsSelected(true, eEventSource.Mouse);
}
}
base.InternalMouseUp(objArg);
}
private Size GetSymbolSize(Graphics g)
{
Size symbolSize = Size.Empty;
if (g == null || string.IsNullOrEmpty(_Symbol)) return symbolSize;
Font symFont = Symbols.GetFont(this.SymbolSize, this.SymbolSet);
symbolSize = TextDrawing.MeasureString(g, "\uF00A", symFont); // Need to do this to get consistent size for the symbol since they are not all the same width we pick widest
int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
symbolSize.Height -= descent;
return symbolSize;
}
private Size _ActualSymbolSize = Size.Empty;
internal Size ActualSymbolSize
{
get
{
return _ActualSymbolSize;
}
}
private bool _MouseOver = false;
/// <summary>
/// Gets whether mouse is over the item.
/// </summary>
[Browsable(false)]
public bool IsMouseOver
{
get { return _MouseOver; }
internal set { _MouseOver = value; }
}
internal Size CheckBoxSize
{
get
{
return _CheckBoxSize;
}
}
private eMouseState _CheckBoxMouseState = eMouseState.None;
/// <summary>
/// Gets the mouse state of the check box part of item if visible.
/// </summary>
[Browsable(false)]
public eMouseState CheckBoxMouseState
{
get { return _CheckBoxMouseState; }
internal set
{
if (_CheckBoxMouseState != value)
{
_CheckBoxMouseState = value;
this.Refresh();
}
}
}
/// <summary>
/// Indicates check-box state if visible.
/// </summary>
[DefaultValue(CheckState.Unchecked), Category("Appearance"), Description("Indicates check-box state if visible.")]
public CheckState CheckState
{
get { return _CheckState; }
set
{
if (value != _CheckState)
{
CheckState oldValue = _CheckState;
_CheckState = value;
OnCheckStateChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when CheckState property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnCheckStateChanged(CheckState oldValue, CheckState newValue)
{
ListBoxAdv listBox = this.ContainerControl as ListBoxAdv;
if (listBox != null)
{
ListBoxAdvItemCheckEventArgs e = new ListBoxAdvItemCheckEventArgs(this, newValue);
listBox.ListItemCheckStateChanged(e);
if (e.Cancel)
_CheckState = oldValue;
}
//OnPropertyChanged(new PropertyChangedEventArgs("CheckState"));
this.Refresh();
}
// Fields...
private Image _Image;
private bool _IsSelected = false;
/// <summary>
/// Gets or sets whether item is selected.
/// </summary>
[Browsable(false), DefaultValue(false)]
public bool IsSelected
{
get { return _IsSelected; }
set
{
if (value != _IsSelected)
{
SetIsSelected(value, eEventSource.Code);
}
}
}
/// <summary>
/// Called when IsSelected property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnIsSelectedChanged(bool oldValue, bool newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("IsSelected"));
this.Refresh();
}
/// <summary>
/// Sets selected state of the item including the source of the action that caused the change.
/// </summary>
/// <param name="isSelected"></param>
/// <param name="source"></param>
public void SetIsSelected(bool isSelected, eEventSource source)
{
bool oldValue = _IsSelected;
ListBoxAdv listBox = this.ContainerControl as ListBoxAdv;
_IsSelected = isSelected;
if (listBox != null)
{
listBox.OnListBoxItemSelectedChanged(this, source);
}
OnIsSelectedChanged(oldValue, isSelected);
}
/// <summary>
/// Indicates whether item changes its background colors when mouse is over the item.
/// </summary>
[DefaultValue(false), Category("Behavior"), Description("Indicates whether item changes its background colors when mouse is over the item")]
public bool HotTracking
{
get { return _HotTracking; }
set
{
if (value != _HotTracking)
{
bool oldValue = _HotTracking;
_HotTracking = value;
OnHotTrackingChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when HotTracking property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnHotTrackingChanged(bool oldValue, bool newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("HotTracking"));
}
/// <summary>
/// Specifies image displayed on the item.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Specifies image displayed on the item.")]
public Image Image
{
get { return _Image; }
set
{
if (value != _Image)
{
Image oldValue = _Image;
_Image = value;
OnImageChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Image property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnImageChanged(Image oldValue, Image newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("Image"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private Color _SymbolColor = Color.Empty;
/// <summary>
/// Gets or sets the color of the Symbol.
/// </summary>
[Category("Appearance"), Description("Indicates color of the Symbol.")]
public Color SymbolColor
{
get { return _SymbolColor; }
set { _SymbolColor = value; this.Refresh(); }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSymbolColor()
{
return !_SymbolColor.IsEmpty;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSymbolColor()
{
this.SymbolColor = Color.Empty;
}
/// <summary>
/// Gets the realized symbol string.
/// </summary>
[Browsable(false)]
public string SymbolRealized
{
get { return _SymbolRealized; }
}
private string _Symbol = "", _SymbolRealized = "";
/// <summary>
/// Indicates the symbol displayed on face of the button instead of the image. Setting the symbol overrides the image setting.
/// </summary>
[DefaultValue(""), Category("Appearance"), Description("Indicates the symbol displayed on face of the button instead of the image. Setting the symbol overrides the image setting.")]
[Editor("DevComponents.DotNetBar.Design.SymbolTypeEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
public string Symbol
{
get { return _Symbol; }
set
{
if (value != _Symbol)
{
string oldValue = _Symbol;
_Symbol = value;
OnSymbolChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Symbol property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnSymbolChanged(string oldValue, string newValue)
{
if (string.IsNullOrEmpty(newValue))
_SymbolRealized = "";
else
_SymbolRealized = Symbols.GetSymbol(newValue);
//OnPropertyChanged(new PropertyChangedEventArgs("Symbol"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private eSymbolSet _SymbolSet = eSymbolSet.Awesome;
/// <summary>
/// Gets or sets the symbol set used to represent the Symbol.
/// </summary>
[Browsable(false), DefaultValue(eSymbolSet.Awesome)]
public eSymbolSet SymbolSet
{
get { return _SymbolSet; }
set
{
if (_SymbolSet != value)
{
eSymbolSet oldValue = _SymbolSet;
_SymbolSet = value;
OnSymbolSetChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when SymbolSet property value changes.
/// </summary>
/// <param name="oldValue">Indciates old value</param>
/// <param name="newValue">Indicates new value</param>
protected virtual void OnSymbolSetChanged(eSymbolSet oldValue, eSymbolSet newValue)
{
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private float _SymbolSize = 13f;
/// <summary>
/// Indicates the size of the symbol in points.
/// </summary>
[DefaultValue(13f), Category("Appearance"), Description("Indicates the size of the symbol in points.")]
public float SymbolSize
{
get { return _SymbolSize; }
set
{
if (value != _SymbolSize)
{
float oldValue = _SymbolSize;
_SymbolSize = value;
OnSymbolSizeChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when SymbolSize property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnSymbolSizeChanged(float oldValue, float newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("SymbolSize"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private Color[] _BackColors = null;
/// <summary>
/// Indicates the array of colors that when set are used to draw the background of the item.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates the array of colors that when set are used to draw the background of the item."), TypeConverter(typeof(ArrayConverter))]
public Color[] BackColors
{
get
{
return _BackColors;
}
set
{
if (_BackColors != value)
{
_BackColors = value;
//OnPropertyChanged(new PropertyChangedEventArgs("Colors"));
this.Refresh();
}
}
}
private Color _TextColor = Color.Empty;
/// <summary>
/// Gets or sets the color of the text.
/// </summary>
[Category("Columns"), Description("Indicates color of text.")]
public Color TextColor
{
get { return _TextColor; }
set { _TextColor = value; this.Refresh(); }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTextColor()
{
return !_TextColor.IsEmpty;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTextColor()
{
this.TextColor = Color.Empty;
}
/// <summary>
/// Gets or sets the text associated with this item.
/// </summary>
[System.ComponentModel.Browsable(true), DevCoBrowsable(true), Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor)), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("The text contained in the item."), System.ComponentModel.Localizable(true), System.ComponentModel.DefaultValue("")]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
private eButtonTextAlignment _TextAlignment = eButtonTextAlignment.Left;
/// <summary>
/// Gets or sets the text alignment. Default value is left.
/// </summary>
[Browsable(true), DefaultValue(eButtonTextAlignment.Left), Category("Appearance"), Description("Indicates text alignment.")]
public eButtonTextAlignment TextAlignment
{
get { return _TextAlignment; }
set
{
_TextAlignment = value;
this.Refresh();
}
}
#endregion
#region Markup Implementation
/// <summary>
/// Gets whether item supports text markup. Default is false.
/// </summary>
protected override bool IsMarkupSupported
{
get { return _EnableMarkup; }
}
private bool _EnableMarkup = true;
/// <summary>
/// Gets or sets whether text-markup support is enabled for items Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the item instead of it being parsed as text-markup.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether text-markup support is enabled for items Text property.")]
public bool EnableMarkup
{
get { return _EnableMarkup; }
set
{
if (_EnableMarkup != value)
{
_EnableMarkup = value;
NeedRecalcSize = true;
OnTextChanged();
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
internal class ListBoxItemPainter : IOffice2007Painter
{
/// <summary>
/// Paints ListBoxItem.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public virtual void Paint(ListBoxItemRendererEventArgs e) { }
#region IOffice2007Painter Members
private Office2007ColorTable _ColorTable = null; //new Office2007ColorTable();
public Office2007ColorTable ColorTable
{
get
{
return _ColorTable;
}
set
{
_ColorTable = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for the Slider item rendering events.
/// </summary>
public class ListBoxItemRendererEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the reference to the item being rendered.
/// </summary>
public ListBoxItem Item = null;
/// <summary>
/// Gets or sets the reference to graphics object.
/// </summary>
public Graphics Graphics = null;
internal ItemPaintArgs ItemPaintArgs = null;
/// <summary>
/// Creates new instance of the object and initializes it with default values.
/// </summary>
/// <param name="item">Reference to the ListBoxItem being rendered.</param>
/// <param name="g">Reference to the graphics object.</param>
public ListBoxItemRendererEventArgs(ListBoxItem item, Graphics g)
{
this.Item = item;
this.Graphics = g;
}
}
}

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Defines color table for ListBoxItem.
/// </summary>
public class OfficeListBoxItemColorTable
{
/// <summary>
/// Specifies default state color table.
/// </summary>
public OfficeListBoxItemStateColorTable Default = new OfficeListBoxItemStateColorTable();
/// <summary>
/// Specifies mouse over state color table.
/// </summary>
public OfficeListBoxItemStateColorTable MouseOver = new OfficeListBoxItemStateColorTable();
/// <summary>
/// Specifies selected state color table.
/// </summary>
public OfficeListBoxItemStateColorTable Selected = new OfficeListBoxItemStateColorTable();
}
/// <summary>
/// Defines single state color table for ListBoxItem.
/// </summary>
public class OfficeListBoxItemStateColorTable
{
/// <summary>
/// Initializes a new instance of the OfficeListBoxItemStateColorTable class.
/// </summary>
public OfficeListBoxItemStateColorTable()
{
}
/// <summary>
/// Initializes a new instance of the OfficeListBoxItemStateColorTable class.
/// </summary>
/// <param name="textColor"></param>
/// <param name="backColors"></param>
/// <param name="backColorsGradientAngle"></param>
/// <param name="backColorsPositions"></param>
public OfficeListBoxItemStateColorTable(Color textColor, Color[] backColors, int backColorsGradientAngle, float[] backColorsPositions)
{
TextColor = textColor;
BackColors = backColors;
BackColorsGradientAngle = backColorsGradientAngle;
BackColorsPositions = backColorsPositions;
}
/// <summary>
/// Initializes a new instance of the OfficeListBoxItemStateColorTable class.
/// </summary>
/// <param name="textColor"></param>
public OfficeListBoxItemStateColorTable(Color textColor)
{
TextColor = textColor;
}
/// <summary>
/// Indicates item text color.
/// </summary>
public Color TextColor = Color.Black;
/// <summary>
/// Gets or sets the background colors for the item.
/// </summary>
public Color[] BackColors = new Color[0];
/// <summary>
/// Gets or sets the back colors gradient angle if there is more than one color in BackColors array.
/// </summary>
public int BackColorsGradientAngle = 90;
/// <summary>
/// Gets or sets the gradient colors positions if there is more than one color in BackColors array.
/// </summary>
public float[] BackColorsPositions = new float[0];
}
}

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using DevComponents.Editors.DateTimeAdv;
namespace DevComponents.DotNetBar.Rendering
{
internal class OfficeListBoxItemPainter : ListBoxItemPainter
{
#region Implementation
/// <summary>
/// Paints StepItem.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public override void Paint(ListBoxItemRendererEventArgs e)
{
Graphics g = e.ItemPaintArgs.Graphics;
ListBoxItem item = e.Item;
ListBoxAdv listBox = e.ItemPaintArgs.ContainerControl as ListBoxAdv;
bool checkBoxes = false;
bool useMnemonic = true;
if (listBox != null)
{
checkBoxes = listBox.CheckBoxesVisible;
useMnemonic = listBox.UseMnemonic;
}
OfficeListBoxItemColorTable table = ColorTable.ListBoxItem;
OfficeListBoxItemStateColorTable ct = item.IsSelected ? table.Selected : table.Default;
if (item.HotTracking && item.IsMouseOver)
ct = table.MouseOver;
Rectangle r = item.Bounds;
if (checkBoxes)
{
Office2007CheckBoxStateColorTable cbt = GetCheckBoxStateColorTable(item.CheckBoxMouseState);
Size checkBoxSize = Dpi.Size(item.CheckBoxSize);
Rectangle cbr = new Rectangle(r.X + 2, r.Y + (r.Height - checkBoxSize.Height) / 2, checkBoxSize.Width, checkBoxSize.Height);
_CheckBoxPainter.PaintCheckBox(g, cbr, cbt, item.CheckState);
int checkBoxTextSpacing = Dpi.Width(ListBoxItem.CheckBoxTextSpacing);
r.X += checkBoxSize.Width + checkBoxTextSpacing - 1;
r.Width -= checkBoxSize.Width + checkBoxTextSpacing - 1;
item.CheckBoxBounds = cbr;
}
if (ct.BackColors != null && ct.BackColors.Length > 0 || item.BackColors != null && item.BackColors.Length > 0)
{
using (Brush brush = DisplayHelp.CreateBrush(r, (item.BackColors != null && item.BackColors.Length > 0) ? item.BackColors : ct.BackColors, ct.BackColorsGradientAngle, ct.BackColorsPositions))
{
g.FillRectangle(brush, r);
}
}
Color textColor = ct.TextColor;
if (!string.IsNullOrEmpty(item.SymbolRealized))
{
Color symbolColor = item.SymbolColor;
if (symbolColor.IsEmpty) symbolColor = textColor;
TextDrawing.DrawStringLegacy(g, item.SymbolRealized, Symbols.GetFont(item.SymbolSize, item.SymbolSet),
symbolColor, new Rectangle(r.X, r.Y + r.Height / 2, 0, 0), eTextFormat.Default | eTextFormat.VerticalCenter);
int imageSize = item.ActualSymbolSize.Width + Dpi.Width(ListBoxItem.ImageTextSpacing);
r.Width -= imageSize;
r.X += imageSize;
}
else if (item.Image != null)
{
Size imgSize = Dpi.ImageSize(item.Image.Size);
g.DrawImage(item.Image, new Rectangle(r.X, r.Y + (r.Height - imgSize.Height) / 2, imgSize.Width, imgSize.Height));
int imageSize = imgSize.Width + Dpi.Width(ListBoxItem.ImageTextSpacing);
r.Width -= imageSize;
r.X += imageSize;
}
if (!string.IsNullOrEmpty(item.Text))
{
if (checkBoxes) { r.X += 1; r.Width -= 1; }
if (!item.TextColor.IsEmpty) textColor = item.TextColor;
Font font = e.ItemPaintArgs.Font;
if (item.TextMarkupBody == null)
{
eTextFormat textFormat = eTextFormat.Default | eTextFormat.VerticalCenter;
if (item.TextAlignment == eButtonTextAlignment.Center)
{
textFormat |= eTextFormat.HorizontalCenter;
}
else if (item.TextAlignment == eButtonTextAlignment.Right)
{
textFormat |= eTextFormat.Right;
}
if (!useMnemonic)
textFormat |= eTextFormat.NoPrefix;
TextDrawing.DrawString(g, item.Text, font, textColor, r, textFormat);
}
else
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, e.ItemPaintArgs.RightToLeft);
d.HotKeyPrefixVisible = false;
d.ContextObject = item;
Rectangle mr = new Rectangle(r.X, r.Y + (r.Height - item.TextMarkupBody.Bounds.Height) / 2, item.TextMarkupBody.Bounds.Width, item.TextMarkupBody.Bounds.Height);
item.TextMarkupBody.Bounds = mr;
item.TextMarkupBody.Render(d);
}
}
}
private Office2007CheckBoxStateColorTable GetCheckBoxStateColorTable(eMouseState state)
{
if (state == eMouseState.Down)
return ColorTable.CheckBoxItem.Pressed;
if (state == eMouseState.Hot)
return ColorTable.CheckBoxItem.MouseOver;
return ColorTable.CheckBoxItem.Default;
}
private Office2007CheckBoxItemPainter _CheckBoxPainter;
public Office2007CheckBoxItemPainter CheckBoxPainter
{
get { return _CheckBoxPainter; }
set { _CheckBoxPainter = value; }
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,249 @@
using System;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.Drawing;
using System.Runtime.InteropServices;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for MessageHandler.
/// </summary>
internal class NonClientHook
{
private static ArrayList m_Clients = new ArrayList();
private static Hashtable m_FilterOnThread = new Hashtable();
private static ReaderWriterLock rwClientsListLock;
private static MouseProc m_MouseHook = null;
private delegate IntPtr MouseProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int hookid, MouseProc pfnhook, IntPtr hinst, int threadid);
//[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, EntryPoint = "SetWindowsHookEx")]
//private static extern IntPtr SetWindowsHookExKeyboard(int hookid, KeyboardProc pfnhook, IntPtr hinst, int threadid);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
private static extern bool UnhookWindowsHookEx(IntPtr hhook);
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
private static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);
[DllImport("kernel32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
private static extern int GetCurrentThreadId();
private const int WH_MOUSE = 7;
private const int HC_ACTION = 0;
private const int WH_CALLWNDPROCRET = 12;
private const int WH_CALLWNDPROC = 4;
// Methods
static NonClientHook()
{
NonClientHook.rwClientsListLock = new ReaderWriterLock();
m_MouseHook = new MouseProc(OnMouseHook);
}
public static void RegisterHook(ISkinHook client)
{
if (m_Clients.Contains(client))
return;
if (!m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
HookThread();
LockCookie cookie1 = new LockCookie();
bool readerLockHeld = NonClientHook.rwClientsListLock.IsReaderLockHeld;
if (readerLockHeld)
{
cookie1 = NonClientHook.rwClientsListLock.UpgradeToWriterLock(-1);
}
else
{
NonClientHook.rwClientsListLock.AcquireWriterLock(-1);
}
try
{
m_Clients.Add(client);
}
finally
{
if (readerLockHeld)
{
NonClientHook.rwClientsListLock.DowngradeFromWriterLock(ref cookie1);
}
else
{
NonClientHook.rwClientsListLock.ReleaseWriterLock();
}
}
}
public static void UnregisterHook(ISkinHook client)
{
if (m_Clients.Contains(client))
{
LockCookie cookie1 = new LockCookie();
bool readerLockHeld = NonClientHook.rwClientsListLock.IsReaderLockHeld;
if (readerLockHeld)
{
cookie1 = NonClientHook.rwClientsListLock.UpgradeToWriterLock(-1);
}
else
{
NonClientHook.rwClientsListLock.AcquireWriterLock(-1);
}
try
{
m_Clients.Remove(client);
if (m_Clients.Count == 0)
UnHookThread();
}
finally
{
if (readerLockHeld)
{
NonClientHook.rwClientsListLock.DowngradeFromWriterLock(ref cookie1);
}
else
{
NonClientHook.rwClientsListLock.ReleaseWriterLock();
}
}
}
}
private static void HookThread()
{
if (m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
return;
int id = GetCurrentThreadId();
IntPtr hook = SetWindowsHookEx(WH_MOUSE, m_MouseHook, IntPtr.Zero, id);
m_FilterOnThread.Add(System.Threading.Thread.CurrentThread.GetHashCode(), hook);
}
private static void UnHookThread()
{
if (!m_FilterOnThread.ContainsKey(System.Threading.Thread.CurrentThread.GetHashCode()))
return;
IntPtr hook = (IntPtr)m_FilterOnThread[System.Threading.Thread.CurrentThread.GetHashCode()];
UnhookWindowsHookEx(hook);
m_FilterOnThread.Remove(System.Threading.Thread.CurrentThread.GetHashCode());
}
private static ISkinHook[] GetMessageClients()
{
ISkinHook[] messageClients;
NonClientHook.rwClientsListLock.AcquireReaderLock(-1);
try
{
messageClients = (ISkinHook[])m_Clients.ToArray(typeof(ISkinHook));
}
finally
{
NonClientHook.rwClientsListLock.ReleaseReaderLock();
}
return messageClients;
}
private static unsafe IntPtr OnMouseHook(int nCode, IntPtr wParam, IntPtr lParam)
{
try
{
if (nCode == HC_ACTION)
{
int wParamInt = WinApi.ToInt(wParam);
if (wParamInt == (int)WinApi.WindowsMessages.WM_MOUSEMOVE)
{
MOUSEHOOKSTRUCT* ws = (MOUSEHOOKSTRUCT*)lParam;
PostMouseMove(ws->hwnd, ws->pt.ToPoint());
}
if (wParamInt == (int)WinApi.WindowsMessages.WM_LBUTTONUP)
{
MOUSEHOOKSTRUCT* ws = (MOUSEHOOKSTRUCT*)lParam;
PostMouseUp(ws->hwnd, ws->pt.ToPoint());
}
//CWPRETSTRUCT* ws = (CWPRETSTRUCT*)lParam;
//if (ws->message == (uint)WinApi.WindowsMessages.WM_MOUSEMOVE || ws->message == 0x118)
//{
// PostMouseMove(ws->hwnd, ws->wParam, ws->lParam);
//}
}
IntPtr h = (IntPtr)m_FilterOnThread[System.Threading.Thread.CurrentThread.GetHashCode()];
IntPtr res = CallNextHookEx(h, nCode, wParam, lParam);
return res;
}
catch
{ }
return IntPtr.Zero;
}
public static bool PostMouseMove(IntPtr hWnd, Point mousePos)
{
ISkinHook[] messageClients = GetMessageClients();
foreach (ISkinHook client in messageClients)
{
client.PostMouseMove(hWnd, mousePos);
}
return false;
}
public static bool PostMouseUp(IntPtr hWnd, Point mousePos)
{
ISkinHook[] messageClients = GetMessageClients();
foreach (ISkinHook client in messageClients)
{
client.PostMouseUp(hWnd, mousePos);
}
return false;
}
private struct POINT
{
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
public int x;
public int y;
public Point ToPoint()
{
return new Point(x, y);
}
}
private struct MOUSEHOOKSTRUCT
{
public MOUSEHOOKSTRUCT(POINT pt, IntPtr hwnd, ushort wHitTestCode, IntPtr dwExtraInfo)
{
this.pt = pt;
this.hwnd = hwnd;
this.wHitTestCode = wHitTestCode;
this.dwExtraInfo = dwExtraInfo;
}
public POINT pt;
public IntPtr hwnd;
public ushort wHitTestCode;
public IntPtr dwExtraInfo;
}
}
internal interface ISkinHook
{
void PostMouseMove(IntPtr hWnd, Point mousePos);
void PostMouseUp(IntPtr hWnd, Point mousePos);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,326 @@
#if FRAMEWORK20
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents the PageNavigator control
/// </summary>
[ToolboxBitmap(typeof(PageNavigator), "PageNavigator.PageNavigator.ico"), ToolboxItem(true)]
[DefaultEvent("ValueChanged"), ComVisible(false)] //, Designer(typeof(Design.PageNavigatorDesigner))]
public class PageNavigator : BaseItemControl
{
#region Private Variables
private PageNavigatorItem _PageNavItem; // Navigation item
#endregion
#region Events
/// <summary>
/// Occurs when NavigateNextPage button is clicked
/// </summary>
[Description("Occurs when NavigateNextPage button is clicked.")]
public event EventHandler NavigateNextPage;
/// <summary>
/// Occurs when NavigateToday button is clicked
/// </summary>
[Description("Occurs when NavigateToday button is clicked.")]
public event EventHandler NavigateToday;
/// <summary>
/// Occurs when NavigatePreviousPage button is clicked
/// </summary>
[Description("Occurs when NavigatePreviousPage button is clicked.")]
public event EventHandler NavigatePreviousPage;
#endregion
/// <summary>
/// Constructor
/// </summary>
public PageNavigator()
{
_PageNavItem = new PageNavigatorItem();
_PageNavItem.Style = eDotNetBarStyle.StyleManagerControlled;
this.Size = _PageNavItem.Size;
this.HostItem = _PageNavItem;
HookEvents(true);
}
#region DefaultSize
/// <summary>
/// DefaultSize
/// </summary>
protected override Size DefaultSize
{
get
{
// Set a default size based upon
// the current object layout orientation
int m = SystemInformation.VerticalScrollBarWidth;
int n = m * 3;
if (_PageNavItem != null &&
_PageNavItem.Orientation == eOrientation.Horizontal)
{
return (new Size(n, m));
}
return (new Size(m, n));
}
}
#endregion
#region Public properties
#region Orientation
/// <summary>
/// Gets or sets the layout orientation. Default value is horizontal.
/// </summary>
[DefaultValue(eOrientation.Horizontal), Category("Appearance")]
[Description("Indicates control layout orientation.")]
public eOrientation Orientation
{
get { return (_PageNavItem.Orientation); }
set
{
if (_PageNavItem.Orientation != value)
{
_PageNavItem.Orientation = value;
this.RecalcLayout();
}
}
}
#endregion
#region PreviousPageTooltip
/// <summary>
/// Gets or sets the tooltip for the PreviousPage button of the control
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates tooltip for the PreviousPage button of the control.")]
public string PreviousPageTooltip
{
get { return (_PageNavItem.PreviousPageTooltip); }
set { _PageNavItem.PreviousPageTooltip = value; }
}
#endregion
#region TodayTooltip
/// <summary>
/// Gets or sets the tooltip for the Today button
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates tooltip for the TodayPage button of the control.")]
public string TodayTooltip
{
get { return (_PageNavItem.TodayTooltip); }
set { _PageNavItem.TodayTooltip = value; }
}
#endregion
#region NextPageTooltip
/// <summary>
/// Gets or sets the tooltip for the NextPage button
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates tooltip for the NextPage button of the control.")]
public string NextPageTooltip
{
get { return (_PageNavItem.NextPageTooltip); }
set { _PageNavItem.NextPageTooltip = value; }
}
#endregion
#region Style
/// <summary>
/// Gets/Sets the visual style for the control.
/// </summary>
[Browsable(false), DefaultValue(eDotNetBarStyle.StyleManagerControlled)]
public override eDotNetBarStyle Style
{
get
{
return base.Style;
}
set
{
base.Style = value;
}
}
#endregion
#endregion
#region HookEvents
/// <summary>
/// Hooks or unhooks our control events
/// </summary>
/// <param name="hook">true to hook, false to unhook</param>
private void HookEvents(bool hook)
{
if (hook == true)
{
_PageNavItem.NavigatePreviousPage += PageNavNavigatePreviousPage;
_PageNavItem.NavigateNextPage += PageNavNavigateNextPage;
_PageNavItem.NavigateToday += PageNavNavigateToday;
}
else
{
_PageNavItem.NavigatePreviousPage -= PageNavNavigatePreviousPage;
_PageNavItem.NavigateNextPage -= PageNavNavigateNextPage;
_PageNavItem.NavigateToday -= PageNavNavigateToday;
}
}
#endregion
#region Event handling
#region PageNav_NavigatePreviousPage
/// <summary>
/// Handles NavigatePreviousPage events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PageNavNavigatePreviousPage(object sender, EventArgs e)
{
OnNavigatePreviousPage();
}
/// <summary>
/// Raises the NavigatePreviousPage event
/// </summary>
private void OnNavigatePreviousPage()
{
if (NavigatePreviousPage != null)
NavigatePreviousPage(this, EventArgs.Empty);
}
#endregion
#region PageNav_NavigateToday
/// <summary>
/// Handles NavigateToday events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PageNavNavigateToday(object sender, EventArgs e)
{
OnNavigateToday();
}
/// <summary>
/// Raises the NavigateToday event
/// </summary>
private void OnNavigateToday()
{
if (NavigateToday != null)
NavigateToday(this, EventArgs.Empty);
}
#endregion
#region PageNav_NavigateNextPage
/// <summary>
/// Handles NavigateNextPage events
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PageNavNavigateNextPage(object sender, EventArgs e)
{
OnNavigateNextPage();
}
/// <summary>
/// Raises the NavigateNextPage event
/// </summary>
private void OnNavigateNextPage()
{
if (NavigateNextPage != null)
NavigateNextPage(this, EventArgs.Empty);
}
#endregion
#endregion
#region RecalcLayout
/// <summary>
/// Forces the button to perform internal layout.
/// </summary>
public override void RecalcLayout()
{
base.RecalcLayout();
}
#endregion
#region Dispose
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing"></param>
protected override void Dispose(bool disposing)
{
if (disposing == true)
HookEvents(false);
base.Dispose(disposing);
}
#endregion
}
#region enums
/// <summary>
/// PageNavigator buttons
/// </summary>
public enum PageNavigatorButton
{
/// <summary>
/// Previous page
/// </summary>
PreviousPage,
/// <summary>
/// Today
/// </summary>
Today,
/// <summary>
/// Next page
/// </summary>
NextPage
}
#endregion
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false)]
[Designer("DevComponents.DotNetBar.Design.PageSliderPageDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class PageSliderPage : Panel
{
#region Constructor
#endregion
#region Implementation
private int _PageNumber = 1;
/// <summary>
/// Gets or sets page number. Page number determines the order in which pages are displayed inside of the PageSlider control.
/// </summary>
[DefaultValue(1), Category("Behavior"), Description("Indicates page number. Page number determines the order in which pages are displayed inside of the PageSlider control.")]
public int PageNumber
{
get { return _PageNumber; }
set
{
if (value != _PageNumber)
{
int oldValue = _PageNumber;
_PageNumber = value;
OnPageNumberChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when PageNumber property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnPageNumberChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("PageNumber"));
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
PageSlider parent = this.Parent as PageSlider;
if (parent != null) parent.StartPageDrag();
}
base.OnMouseDown(e);
}
#endregion
}
}

View File

@@ -0,0 +1,267 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents control which visually indicates current step in a sequence.
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmap(typeof(StepIndicator), "Controls.StepIndicator.ico")]
public class StepIndicator : Control
{
#region Constructor
/// <summary>
/// Initializes a new instance of the StepIndicator class.
/// </summary>
public StepIndicator()
{
this.SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.Opaque |
ControlStyles.ResizeRedraw |
ControlStyles.DoubleBuffer |
ControlStyles.StandardDoubleClick | ControlStyles.StandardClick, true);
this.SetStyle(ControlStyles.Selectable, false);
}
#endregion
#region Implementation
protected override void OnPaint(PaintEventArgs e)
{
StepIndicatorColorTable colors = GetColors();
Color backColor = colors.BackgroundColor;
Color indicatorColor = colors.IndicatorColor;
Graphics g = e.Graphics;
Rectangle r = this.ClientRectangle;
using (SolidBrush brush = new SolidBrush(backColor))
g.FillRectangle(brush, r);
int currentStep = GetCurrentStep() - 1;
if (currentStep >= 0)
{
int stepCount = _StepCount;
Rectangle indicatorBounds;
if (_Orientation == eOrientation.Horizontal)
{
int indicatorWidth = (int)Math.Ceiling((double)r.Width / stepCount);
indicatorBounds = new Rectangle(r.X + indicatorWidth * currentStep, r.Y, indicatorWidth, r.Height);
}
else
{
int indicatorHeight = (int)Math.Ceiling((double)r.Height / stepCount);
indicatorBounds = new Rectangle(r.X, r.Y + indicatorHeight * currentStep, r.Width, indicatorHeight);
}
if (r.Width > 0 && r.Height > 0)
{
using (SolidBrush brush = new SolidBrush(indicatorColor))
g.FillRectangle(brush, indicatorBounds);
}
}
base.OnPaint(e);
}
private StepIndicatorColorTable GetColors()
{
if (!_IndicatorColor.IsEmpty && !_BackgroundColor.IsEmpty)
return new StepIndicatorColorTable(_BackgroundColor, _IndicatorColor);
if (GlobalManager.Renderer is Office2007Renderer)
{
return ((Office2007Renderer)GlobalManager.Renderer).ColorTable.StepIndicator;
}
else
return new StepIndicatorColorTable(Color.White, Color.MediumSeaGreen);
}
private int GetCurrentStep()
{
return Math.Max(0, Math.Min(_StepCount, _CurrentStep));
}
private int _StepCount = 10;
/// <summary>
/// Gets or sets the total number of steps that control will track. Default value is 10.
/// </summary>
[DefaultValue(10), Category("Behavior"), Description("Indicates total number of steps that control will track.")]
public int StepCount
{
get { return _StepCount; }
set
{
value = Math.Max(1, value);
if (value != _StepCount)
{
int oldValue = _StepCount;
_StepCount = value;
OnStepCountChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when StepCount property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnStepCountChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("StepCount"));
this.Invalidate();
}
private int _CurrentStep = 1;
/// <summary>
/// Gets or sets the current step in sequence. Current step should be less or equal than StepCount.
/// </summary>
[DefaultValue(1), Category("Behavior"), Description("Indicates current step in sequence..")]
public int CurrentStep
{
get { return _CurrentStep; }
set
{
if (value != _CurrentStep)
{
int oldValue = _CurrentStep;
_CurrentStep = value;
OnCurrentStepChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when CurrentStep property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnCurrentStepChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("CurrentStep"));
this.Invalidate();
}
private static readonly Color DefaultBackgroundColor = Color.Empty;
private Color _BackgroundColor = DefaultBackgroundColor;
/// <summary>
/// Gets or sets the background color of the control.
/// </summary>
[Category("Appearance"), Description("Indicates background color of control.")]
public Color BackgroundColor
{
get { return _BackgroundColor; }
set { _BackgroundColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeBackgroundColor()
{
return _BackgroundColor != DefaultBackgroundColor;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBackgroundColor()
{
this.BackgroundColor = DefaultBackgroundColor;
}
private static readonly Color DefaultIndicatorColor = Color.Empty;
private Color _IndicatorColor = DefaultIndicatorColor;
/// <summary>
/// Gets or sets the color of the current step indicator.
/// </summary>
[Category("Appearance"), Description("Indicates color of current step indicator.")]
public Color IndicatorColor
{
get { return _IndicatorColor; }
set { _IndicatorColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeIndicatorColor()
{
return _IndicatorColor != DefaultIndicatorColor;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetIndicatorColor()
{
this.IndicatorColor = DefaultIndicatorColor;
}
private eOrientation _Orientation = eOrientation.Horizontal;
/// <summary>
/// Indicates the control orientation.
/// </summary>
[Category("Appearance"), DefaultValue(eOrientation.Horizontal), Description("Indicates the control orientation.")]
public eOrientation Orientation
{
get { return _Orientation; }
set
{
if (value != _Orientation)
{
eOrientation oldValue = _Orientation;
_Orientation = value;
OnOrientationChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Orientation property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnOrientationChanged(eOrientation oldValue, eOrientation newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("Orientation"));
this.Invalidate();
}
protected override Size DefaultSize
{
get
{
return new Size(400,4);
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
public override System.Drawing.Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), EditorBrowsable(EditorBrowsableState.Never)]
public override System.Drawing.Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,745 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Security.Permissions;
using System.Runtime.InteropServices;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar.Controls
{
internal class PopupControlHost : ToolStripDropDown
{
#region Constructor
private ePopupResizeEdge _ResizeEdge = ePopupResizeEdge.None;
private Rectangle _ResizeGripBounds = Rectangle.Empty;
private bool _CanResizeHostControl = false;
private bool _CanResizePopup = false;
private bool _RefreshSize = false;
private static readonly Size ResizeGripSize = new Size(16, 16);
public PopupControlHost()
{
this.AutoSize = false;
this.Padding = System.Windows.Forms.Padding.Empty;
this.Margin = System.Windows.Forms.Padding.Empty;
}
#endregion
#region Implementation
protected override void OnClosing(ToolStripDropDownClosingEventArgs e)
{
Control hostControl = GetHostedControl();
if (hostControl != null)
hostControl.SizeChanged -= HostControlSizeChanged;
base.OnClosing(e);
}
protected override void OnPaint(PaintEventArgs e)
{
ResizeGripBounds = Rectangle.Empty;
Size resizeGripSize = Dpi.Size(ResizeGripSize);
if (IsResizeEnabled(ePopupResizeEdge.BottomLeft))
{
ResizeGripColors colors = GetColors();
using (SolidBrush brush = new SolidBrush(colors.BackColor))
e.Graphics.FillRectangle(brush, 1, Height - resizeGripSize.Height, Width - 2, resizeGripSize.Height - 1);
ResizeGripBounds = new Rectangle(1, Height - resizeGripSize.Height, resizeGripSize.Width, resizeGripSize.Height);
ResizeHandlePainter.DrawResizeHandle(e.Graphics, ResizeGripBounds, colors.GripLightColor, colors.GripColor, true);
}
else if (IsResizeEnabled(ePopupResizeEdge.BottomRight))
{
ResizeGripColors colors = GetColors();
using (SolidBrush brush = new SolidBrush(colors.BackColor))
e.Graphics.FillRectangle(brush, 1, Height - resizeGripSize.Height, Width - 2, resizeGripSize.Height - 1);
ResizeGripBounds = new Rectangle(Width - resizeGripSize.Width - 1, Height - resizeGripSize.Height, resizeGripSize.Width, resizeGripSize.Height);
ResizeHandlePainter.DrawResizeHandle(e.Graphics, ResizeGripBounds, colors.GripLightColor, colors.GripColor, false);
}
base.OnPaint(e);
}
private ResizeGripColors _ResizeGripColors;
private ResizeGripColors GetColors()
{
return _ResizeGripColors;
}
#region ResizeGripColors
private struct ResizeGripColors
{
public Color BackColor;
public Color GripLightColor;
public Color GripColor;
/// <summary>
/// Initializes a new instance of the ResizeGripColors structure.
/// </summary>
/// <param name="backColor"></param>
/// <param name="gripLightColor"></param>
/// <param name="gripColor"></param>
public ResizeGripColors(Color backColor, Color gripLightColor, Color gripColor)
{
BackColor = backColor;
GripLightColor = gripLightColor;
GripColor = gripColor;
}
}
#endregion
private bool _PopupUserSize = false;
/// <summary>
/// Gets whether popup has been resized by end-user.
/// </summary>
public bool PopupUserSize
{
get { return _PopupUserSize; }
set { _PopupUserSize = value; }
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (!_CanResizePopup)
{
UpdateHostControlSize();
_PopupUserSize = true;
}
}
protected void HostControlSizeChanged(object sender, EventArgs e)
{
if (!_CanResizeHostControl)
UpdateContentBasedSize(-1);
}
public new void Show(int x, int y)
{
Show(x, y, -1, -1);
}
public void Show(int x, int y, int width, int height)
{
if (GlobalManager.Renderer is Office2007Renderer)
{
Office2007ColorTable table = ((Office2007Renderer)GlobalManager.Renderer).ColorTable;
_ResizeGripColors = new ResizeGripColors(table.Form.BackColor, table.LegacyColors.SplitterBackground2, table.LegacyColors.BarStripeColor);
}
else
_ResizeGripColors = new ResizeGripColors(SystemColors.ButtonFace, Color.White, SystemColors.ControlDark);
Control hostControl = GetHostedControl();
if (hostControl == null)
return;
_CanResizeHostControl = true;
_CanResizePopup = true;
this.Size = new Size(1, 1);
base.Show(x, y);
_CanResizeHostControl = false;
_CanResizePopup = false;
UpdateContentBasedSize(width);
if (_CloseButtonVisible && IsResizeGripShown)
{
if (_CloseButtonController == null)
{
ButtonItem button = new ButtonItem();
button.Symbol = "\uf00d";
button.SymbolSize = 8;
button.Style = eDotNetBarStyle.StyleManagerControlled;
button.ButtonStyle = eButtonStyle.ImageAndText;
button.LeftInternal = 1;
button.Click += new EventHandler(ClosePopupButtonClick);
_CloseButtonController = new BaseItemController(button, this);
button.RecalcSize();
button.TopInternal = this.Height - button.HeightInternal - 1;
}
}
else if (_CloseButtonController != null)
{
_CloseButtonController.Dispose();
_CloseButtonController = null;
}
if (_RefreshSize)
UpdateHostControlSize();
if (y > Top && y <= Bottom)
{
if (_ParentControlBounds.IsEmpty)
Top = y - Height - (height != -1 ? height : 0);
else
Top = _ParentControlBounds.Y - Height;
//ePopupResizeEdge previous = ResizeEdge;
//if (ResizeEdge == ePopupResizeEdge.BottomLeft)
// ResizeEdge = ePopupResizeEdge.None; // ePopupResizeEdge.TopLeft;
//else if (ResizeEdge == ePopupResizeEdge.BottomRight)
// ResizeEdge = ePopupResizeEdge.None; // ePopupResizeEdge.TopRight;
//if (ResizeEdge != previous)
// UpdateHostControlSize();
}
hostControl.SizeChanged += HostControlSizeChanged;
}
private Rectangle _ParentControlBounds = Rectangle.Empty;
public Rectangle ParentControlBounds
{
get { return _ParentControlBounds; }
set { _ParentControlBounds = value; }
}
private void ClosePopupButtonClick(object sender, EventArgs e)
{
this.Close(ToolStripDropDownCloseReason.CloseCalled);
}
BaseItemController _CloseButtonController = null;
protected void UpdateContentBasedSize(int proposedWidth)
{
if (_CanResizePopup)
return;
_CanResizeHostControl = true;
try
{
Rectangle bounds = Bounds;
bounds.Size = SizeFromContent(proposedWidth);
if (!IsResizeEnabled(ePopupResizeEdge.None))
{
if (proposedWidth > 0 && bounds.Width - 2 > proposedWidth)
if (!IsResizeEnabled(ePopupResizeEdge.Right))
bounds.X -= bounds.Width - 2 - proposedWidth;
}
Bounds = bounds;
}
finally
{
_CanResizeHostControl = false;
}
}
protected void UpdateHostControlSize()
{
if (_CanResizeHostControl)
return;
_CanResizePopup = true;
try
{
Control hostedControl = GetHostedControl();
if (hostedControl != null)
{
Rectangle bounds = hostedControl.Bounds;
if (IsResizeEnabled(ePopupResizeEdge.TopLeft) || IsResizeEnabled(ePopupResizeEdge.TopRight))
bounds.Location = new Point(1, Dpi.Height(ResizeGripSize.Height));
else
bounds.Location = new Point(1, 1);
bounds.Width = ClientRectangle.Width - 2;
bounds.Height = ClientRectangle.Height - 2;
if (IsResizeGripShown)
bounds.Height -= Dpi.Height(ResizeGripSize.Height);
if (bounds.Size != hostedControl.Size)
hostedControl.Size = bounds.Size;
if (bounds.Location != hostedControl.Location)
hostedControl.Location = bounds.Location;
if (_CloseButtonController != null)
{
_CloseButtonController.Item.TopInternal = this.Height - _CloseButtonController.Item.HeightInternal - 1;
}
}
}
finally
{
_CanResizePopup = false;
}
}
public Control GetHostedControl()
{
if (Items.Count > 0)
{
ToolStripControlHost host = Items[0] as ToolStripControlHost;
if (host != null)
return host.Control;
}
return null;
}
public bool IsResizeEnabled(ePopupResizeEdge edge)
{
return (ResizeEdge & edge) == edge;
}
protected Size SizeFromContent(int proposedWidth)
{
Size contentSize = Size.Empty;
_RefreshSize = false;
// Fetch hosted control.
Control hostedControl = GetHostedControl();
if (hostedControl != null)
{
if (IsResizeEnabled(ePopupResizeEdge.TopLeft) || IsResizeEnabled(ePopupResizeEdge.TopRight))
hostedControl.Location = new Point(1, Dpi.Height16);
else
hostedControl.Location = new Point(1, 1);
contentSize = SizeFromClientSize(hostedControl.Size);
// Use minimum width (if specified).
if (proposedWidth > 0 && contentSize.Width < proposedWidth)
{
contentSize.Width = proposedWidth;
_RefreshSize = true;
}
}
// If a grip box is shown then add it into the drop down height.
if (IsResizeGripShown)
contentSize.Height += Dpi.Height16;
// Add some additional space to allow for borders.
contentSize.Width += 2;
contentSize.Height += 2;
return contentSize;
}
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override void WndProc(ref Message m)
{
if (!ProcessResizeGripMessages(ref m, false))
base.WndProc(ref m);
}
/// <summary>
/// Processes the resizing messages.
/// </summary>
/// <param name="m">The message.</param>
/// <returns>true, if the WndProc method from the base class shouldn't be invoked.</returns>
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public bool ProcessResizeGripMessages(ref Message m)
{
return ProcessResizeGripMessages(ref m, true);
}
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
private bool ProcessResizeGripMessages(ref Message m, bool contentControl)
{
if (ResizeEdge != ePopupResizeEdge.None)
{
if (m.Msg == (int)WinApi.WindowsMessages.WM_NCHITTEST)
return ProcessNcHitTest(ref m, contentControl);
else if (m.Msg == (int)WinApi.WindowsMessages.WM_GETMINMAXINFO)
return ProcessGetMinMaxInfo(ref m);
}
return false;
}
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
private bool ProcessGetMinMaxInfo(ref Message m)
{
Control hostedControl = GetHostedControl();
if (hostedControl != null)
{
WinApi.MINMAXINFO minmax = (WinApi.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(WinApi.MINMAXINFO));
// Maximum size.
if (hostedControl.MaximumSize.Width != 0)
minmax.maxTrackSize.Width = hostedControl.MaximumSize.Width;
if (hostedControl.MaximumSize.Height != 0)
minmax.maxTrackSize.Height = hostedControl.MaximumSize.Height;
// Minimum size.
minmax.minTrackSize = new Size(32, 32);
if (hostedControl.MinimumSize.Width > minmax.minTrackSize.Width)
minmax.minTrackSize.Width = hostedControl.MinimumSize.Width;
if (hostedControl.MinimumSize.Height > minmax.minTrackSize.Height)
minmax.minTrackSize.Height = hostedControl.MinimumSize.Height;
Marshal.StructureToPtr(minmax, m.LParam, false);
}
return true;
}
private bool ProcessNcHitTest(ref Message m, bool contentControl)
{
Point location = PointToClient(new Point(WinApi.LOWORD(m.LParam), WinApi.HIWORD(m.LParam)));
IntPtr transparent = new IntPtr((int)WinApi.WindowHitTestRegions.TransparentOrCovered);
if (ResizeGripBounds.Contains(location))
{
if (IsResizeEnabled(ePopupResizeEdge.BottomLeft))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.BottomLeftSizeableCorner;
return true;
}
else if (IsResizeEnabled(ePopupResizeEdge.BottomRight))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.BottomRightSizeableCorner;
return true;
}
else if (IsResizeEnabled(ePopupResizeEdge.TopLeft))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.TopLeftSizeableCorner;
return true;
}
else if (IsResizeEnabled(ePopupResizeEdge.TopRight))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.TopRightSizeableCorner;
return true;
}
}
else
{
Rectangle rectClient = ClientRectangle;
if (location.X > rectClient.Right - 3 && location.X <= rectClient.Right && IsResizeEnabled(ePopupResizeEdge.Right))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.RightSizeableBorder;
return true;
}
else if (location.Y > rectClient.Bottom - 3 && location.Y <= rectClient.Bottom && IsResizeEnabled(ePopupResizeEdge.Bottom))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.BottomSizeableBorder;
return true;
}
else if (location.X > -1 && location.X < 3 && IsResizeEnabled(ePopupResizeEdge.Left))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.LeftSizeableBorder;
return true;
}
else if (location.Y > -1 && location.Y < 3 && IsResizeEnabled(ePopupResizeEdge.Top))
{
m.Result = contentControl ? transparent : (IntPtr)WinApi.WindowHitTestRegions.TopSizeableBorder;
return true;
}
}
return false;
}
/// <summary>
/// Type of resize mode, grips are automatically drawn at bottom-left and bottom-right corners.
/// </summary>
public ePopupResizeEdge ResizeEdge
{
get { return _ResizeEdge; }
set
{
if (value != _ResizeEdge)
{
_ResizeEdge = value;
Invalidate();
}
}
}
private bool _CloseButtonVisible = true;
/// <summary>
/// Gets or sets whether Close button is visible in fotter. Resize handle must also be visible in order for close button to render.
/// </summary>
public bool CloseButtonVisible
{
get { return _CloseButtonVisible; }
set
{
_CloseButtonVisible = value;
}
}
/// <summary>
/// Gets resize grip bounds.
/// </summary>
public Rectangle ResizeGripBounds
{
get { return _ResizeGripBounds; }
private set { _ResizeGripBounds = value; }
}
private bool IsResizeGripShown
{
get
{
return (ResizeEdge == ePopupResizeEdge.BottomLeft || ResizeEdge == ePopupResizeEdge.BottomRight);
}
}
#endregion
}
#region ePopupResizeEdge
/// <summary>
/// Specifies the popup resize modes
/// </summary>
public enum ePopupResizeEdge
{
None = 0,
Left = 1,
Top = 2,
Right = 4,
Bottom = 8,
All = (Top | Left | Bottom | Right),
TopLeft = (Top | Left),
TopRight = (Top | Right),
BottomLeft = (Bottom | Left),
BottomRight = (Bottom | Right),
}
#endregion
#region PopupHostController
internal class PopupHostController : IDisposable
{
#region Constructor
private ToolStripControlHost _ControlHost;
private PopupControlHost _PopupControlHost;
private System.Windows.Forms.Padding _Padding = System.Windows.Forms. Padding. Empty;
private System.Windows.Forms.Padding _Margin = new System.Windows.Forms.Padding(1, 1, 1, 1);
public PopupHostController()
{
InitializePopupControlHost();
}
#endregion
#region Implementation
/// <summary>
/// Occurs after popup is closed.
/// </summary>
public event ToolStripDropDownClosedEventHandler Closed;
/// <summary>
/// Raises Closed event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnClosed(ToolStripDropDownClosedEventArgs e)
{
ToolStripDropDownClosedEventHandler handler = Closed;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Occurs before popup is closed and allows canceling.
/// </summary>
public event ToolStripDropDownClosingEventHandler Closing;
/// <summary>
/// Raises Closing event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnClosing(ToolStripDropDownClosingEventArgs e)
{
ToolStripDropDownClosingEventHandler handler = Closing;
if (handler != null)
handler(this, e);
}
private void InitializeHost(Control control)
{
InitializePopupControlHost();
if (control != this.Control)
DisposeToolstripControlHost();
if (_ControlHost == null)
{
_ControlHost = new ToolStripControlHost(control);
_ControlHost.AutoSize = false;
_ControlHost.Padding = this.Padding;
_ControlHost.Margin = this.Margin;
}
_ControlHost.Size = control.Size;
_PopupControlHost.Items.Clear();
_PopupControlHost.Padding = _PopupControlHost.Margin = System.Windows.Forms.Padding.Empty;
_PopupControlHost.Items.Add(_ControlHost);
}
private void InitializePopupControlHost()
{
if (_PopupControlHost == null)
{
_PopupControlHost = new PopupControlHost();
_PopupControlHost.Closed += new ToolStripDropDownClosedEventHandler(DropDownClosed);
_PopupControlHost.Closing += new ToolStripDropDownClosingEventHandler(DropDownClosing);
}
}
private void DropDownClosed(object sender, ToolStripDropDownClosedEventArgs e)
{
OnClosed(e);
}
void DropDownClosing(object sender, ToolStripDropDownClosingEventArgs e)
{
OnClosing(e);
}
/// <summary>
/// Show control on popup at specified location.
/// </summary>
public void Show(Control control, int x, int y)
{
Show(control, x, y, ePopupResizeEdge.None);
}
/// <summary>
/// Shows control on popup at specified location with specified popup resize edges.
/// </summary>
public void Show(Control control, int x, int y, ePopupResizeEdge resizeEdge)
{
Show(control, x, y, -1, -1, resizeEdge);
}
/// <summary>
/// Shows control on popup at specified location and size with specified popup resize edges.
/// </summary>
public void Show(Control control, int x, int y, int width, int height, ePopupResizeEdge resizeEdge)
{
Size controlSize = control.Size;
InitializeHost(control);
_PopupControlHost.ResizeEdge = resizeEdge;
_PopupControlHost.Show(x, y, width, height);
control.Focus();
}
public Rectangle Bounds
{
get
{
return _PopupControlHost.Bounds;
}
}
/// <summary>
/// Hides popup if visible.
/// </summary>
public void Hide()
{
if (_PopupControlHost != null && _PopupControlHost.Visible)
{
_PopupControlHost.Hide();
}
}
private void DisposeToolstripControlHost()
{
if (_ControlHost != null)
{
if (_PopupControlHost != null)
_PopupControlHost.Items.Clear();
_ControlHost.Dispose();
_ControlHost = null;
}
}
public bool AutoClose
{
get
{
return _PopupControlHost.AutoClose;
}
set
{
_PopupControlHost.AutoClose = value;
}
}
public Rectangle ParentControlBounds
{
get { return _PopupControlHost.ParentControlBounds; }
set { _PopupControlHost.ParentControlBounds = value; }
}
/// <summary>
/// Gets whether popup is visible.
/// </summary>
public bool Visible
{
get { return (_PopupControlHost != null && _PopupControlHost.Visible) ? true : false; }
}
/// <summary>
/// Gets the control displayed on popup.
/// </summary>
public Control Control
{
get { return (_ControlHost != null) ? _ControlHost.Control : null; }
}
/// <summary>
/// Gets or sets the popup padding.
/// </summary>
public System.Windows.Forms.Padding Padding
{
get { return _Padding; }
set { _Padding = value; }
}
/// <summary>
/// Gets or sets popup margin.
/// </summary>
public System.Windows.Forms.Padding Margin
{
get { return _Margin; }
set { _Margin = value; }
}
public bool PopupUserSize
{
get
{
if (_PopupControlHost == null) return false;
return _PopupControlHost.PopupUserSize;
}
set
{
if (_PopupControlHost != null)
_PopupControlHost.PopupUserSize = value;
}
}
public bool CloseButtonVisible
{
get
{
if (_PopupControlHost == null) return false;
return _PopupControlHost.CloseButtonVisible;
}
set
{
if (_PopupControlHost != null)
_PopupControlHost.CloseButtonVisible = value;
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
DisposeToolstripControlHost();
if (_PopupControlHost != null)
{
_PopupControlHost.Closed -= new ToolStripDropDownClosedEventHandler(DropDownClosed);
_PopupControlHost.Closing -= new ToolStripDropDownClosingEventHandler(DropDownClosing);
_PopupControlHost.Dispose();
_PopupControlHost = null;
}
}
#endregion
}
#endregion
}

View File

@@ -0,0 +1,286 @@
using System;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents the stand-alone progress bar control.
/// </summary>
[ToolboxBitmap(typeof(ProgressBarX), "Controls.ProgressBarX.ico"), ToolboxItem(true), DefaultEvent("Click"), System.Runtime.InteropServices.ComVisible(false)]
public class ProgressBarX : BaseItemControl
{
#region Private Variables
private ProgressBarItem m_ProgressBar = null;
#endregion
#region Constructor, Dispose
public ProgressBarX()
{
m_ProgressBar = new ProgressBarItem();
m_ProgressBar.Style = eDotNetBarStyle.Office2007;
m_ProgressBar.Minimum = 0;
m_ProgressBar.Maximum = 100;
m_ProgressBar.Value = 0;
m_ProgressBar.BackStyle = this.BackgroundStyle;
this.HostItem = m_ProgressBar;
}
#endregion
#region Internal Implementation
protected override void PaintBackground(PaintEventArgs e)
{
// ProgressBarItem shares same background style as control so it will paint itself. This avoids double painting...
Graphics g = e.Graphics;
Rectangle r = this.ClientRectangle;
ElementStyle style = this.GetBackgroundStyle();
if ((!style.Custom || style.BackColor.IsEmpty)&& !this.BackColor.IsEmpty && this.BackColor!=Color.Transparent)
{
DisplayHelp.FillRectangle(g, r, this.BackColor);
}
}
/// <summary>
/// Gets or sets the maximum value of the range of the control.
/// </summary>
[Browsable(true), Description("Gets or sets the maximum value of the range of the control."), Category("Behavior"), DefaultValue(100)]
public int Maximum
{
get
{
return m_ProgressBar.Maximum;
}
set
{
m_ProgressBar.Maximum = value;
}
}
/// <summary>
/// Gets or sets the minimum value of the range of the control.
/// </summary>
[DevCoBrowsable(true), Browsable(true), Description("Gets or sets the minimum value of the range of the control."), Category("Behavior"), DefaultValue(0)]
public int Minimum
{
get
{
return m_ProgressBar.Minimum;
}
set
{
m_ProgressBar.Minimum = value;
}
}
/// <summary>
/// Gets or sets the current position of the progress bar.
/// </summary>
[DevCoBrowsable(true), Browsable(true), Description("Gets or sets the current position of the progress bar."), Category("Behavior"), DefaultValue(0)]
public int Value
{
get { return m_ProgressBar.Value; }
set
{
m_ProgressBar.Value = value;
//this.Invalidate();
//this.Update();
}
}
/// <summary>
/// Gets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar.
/// </summary>
[DevCoBrowsable(true), Browsable(true), Description("Gets or sets the amount by which a call to the PerformStep method increases the current position of the progress bar."), Category("Behavior"), DefaultValue(1)]
public int Step
{
get
{
return m_ProgressBar.Step;
}
set
{
m_ProgressBar.Step = value;
}
}
/// <summary>
/// Advances the current position of the progress bar by the amount of the Step property.
/// </summary>
public void PerformStep()
{
this.Value += m_ProgressBar.Step;
}
/// <summary>
/// Advances the current position of the progress bar by the specified amount.
/// </summary>
/// <param name="value">The amount by which to increment the progress bar's current position. </param>
public void Increment(int value)
{
this.Value += value;
}
/// <summary>
/// Gets or sets the color of the progress chunk.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Gets or sets the color of the progress chunk.")]
public Color ChunkColor
{
get
{
return m_ProgressBar.ChunkColor;
}
set
{
m_ProgressBar.ChunkColor = value;
this.Invalidate();
}
}
/// <summary>
/// Gets whether ChunkColor property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeChunkColor()
{
return (!m_ProgressBar.ChunkColor.IsEmpty);
}
/// <summary>
/// Resets the ChunkColor property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetChunkColor()
{
m_ProgressBar.ChunkColor = Color.Empty;
}
/// <summary>
/// Gets or sets the target gradient color of the progress chunk.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Gets or sets the target gradient color of the progress chunk.")]
public Color ChunkColor2
{
get
{
return m_ProgressBar.ChunkColor2;
}
set
{
m_ProgressBar.ChunkColor2 = value;
this.Invalidate();
}
}
/// <summary>
/// Gets whether ChunkColor property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeChunkColor2()
{
return (!m_ProgressBar.ChunkColor2.IsEmpty);
}
/// <summary>
/// Resets the ChunkColor property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetChunkColor2()
{
m_ProgressBar.ChunkColor2 = Color.Empty;
}
/// <summary>
/// Gets or sets the gradient angle of the progress chunk.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Gets or sets the gradient angle of the progress chunk."), DefaultValue(0)]
public int ChunkGradientAngle
{
get
{
return (int)m_ProgressBar.ChunkGradientAngle;
}
set
{
m_ProgressBar.ChunkGradientAngle = value;
this.Invalidate();
}
}
/// <summary>
/// Gets or sets whether the text inside the progress bar is displayed.
/// </summary>
[Browsable(true), Description("Gets or sets whether the text inside the progress bar is displayed."), Category("Behavior"), DefaultValue(false)]
public bool TextVisible
{
get
{
return m_ProgressBar.TextVisible;
}
set
{
m_ProgressBar.TextVisible = value;
this.Invalidate();
}
}
/// <summary>
/// Gets or sets the type of progress bar used to indicate progress. The Standard style displays the progress based on Minimum, Maximum and current Value.
/// The Marquee type is automatically moving progress bar that is used to indicate an ongoing operation for which the actual duration cannot be estimated.
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(eProgressItemType.Standard), Description("Indicates type of progress bar used to indicate progress.")]
public eProgressItemType ProgressType
{
get { return m_ProgressBar.ProgressType; }
set { m_ProgressBar.ProgressType = value; }
}
/// <summary>
/// Gets or sets the marquee animation speed in milliseconds.
/// </summary>
[Browsable(true), DefaultValue(100), Category("Behavior"), Description("Indicates marquee animation speed in milliseconds.")]
public int MarqueeAnimationSpeed
{
get { return m_ProgressBar.MarqueeAnimationSpeed; }
set { m_ProgressBar.MarqueeAnimationSpeed = value; }
}
/// <summary>
/// Gets or sets the predefined color state table for progress bar. Color specified applies to items with Office 2007 style only. It does not have
/// any effect on other styles. You can use ColorTable to indicate the state of the operation that Progress Bar is tracking. Default value is eProgressBarItemColor.Normal.
/// </summary>
[Browsable(true), DevCoBrowsable(false), DefaultValue(eProgressBarItemColor.Normal), Category("Appearance"), Description("Indicates predefined color of item when Office 2007 style is used.")]
public eProgressBarItemColor ColorTable
{
get { return m_ProgressBar.ColorTable; }
set
{
m_ProgressBar.ColorTable = value;
}
}
[DefaultValue(eOrientation.Horizontal)]
public eOrientation Orientation
{
get { return m_ProgressBar.Orientation; }
set
{
if (m_ProgressBar.Orientation != value)
{
m_ProgressBar.Orientation = value;
this.Invalidate();
}
}
}
/// <summary>
/// Gets the underlying ProgressBarItem
/// </summary>
internal ProgressBarItem ProgressBarItem
{
get { return (m_ProgressBar); }
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
internal class MetroStepItemPainter : StepItemPainter
{
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Defines color table for the StepItem.
/// </summary>
public class OfficeStepItemColorTable
{
/// <summary>
/// Gets or sets the default state StepItem colors.
/// </summary>
public OfficeStepItemStateColorTable Default = new OfficeStepItemStateColorTable();
/// <summary>
/// Gets or sets the mouse over state StepItem colors.
/// </summary>
public OfficeStepItemStateColorTable MouseOver = new OfficeStepItemStateColorTable();
/// <summary>
/// Gets or sets the StepItem colors when mouse is pressed over the item.
/// </summary>
public OfficeStepItemStateColorTable Pressed = new OfficeStepItemStateColorTable();
/// <summary>
/// Gets or sets the StepItem colors when Value property is greater than Minimum property value, i.e. item is reporting progress.
/// Note that only Background color is used when progress indicator is drawn.
/// </summary>
public OfficeStepItemStateColorTable Progress = new OfficeStepItemStateColorTable();
}
}

View File

@@ -0,0 +1,200 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
internal class OfficeStepItemPainter : StepItemPainter
{
#region Implementation
/// <summary>
/// Paints StepItem.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public override void Paint(StepItemRendererEventArgs e)
{
StepItem item = e.Item;
OfficeStepItemColorTable table = ColorTable.StepItem;
OfficeStepItemStateColorTable ct = table.Default;
if (item.HotTracking && item.IsMouseDown)
ct = table.Pressed;
else if (item.HotTracking && item.IsMouseOver)
ct = table.MouseOver;
OfficeStepItemStateColorTable ctProgress = table.Progress;
Rectangle clip = Rectangle.Empty;
Rectangle r = item.Bounds;
int pointerSize = item.GetPointerSize();
Graphics g = e.ItemPaintArgs.Graphics;
GraphicsPath path = GetPath(item, pointerSize);
item.ItemPath = path;
using (Brush brush = DisplayHelp.CreateBrush(path.GetBounds(), (item.BackColors != null && item.BackColors.Length > 0) ? item.BackColors : ct.BackColors, ct.BackColorsGradientAngle, ct.BackColorsPositions))
{
g.FillPath(brush, path);
}
if (item.Value > item.Minimum) // Render progress marker
{
float percent = Math.Min(1, (item.Value / (float)(item.Maximum - item.Minimum)));
if (percent > 0)
{
clip = item.Bounds;
clip.Width = (int)(clip.Width * percent);
}
if (!clip.IsEmpty)
{
Region oldClip = g.Clip;
g.SetClip(clip, CombineMode.Intersect);
using (Brush brush = DisplayHelp.CreateBrush(path.GetBounds(),
(item.ProgressColors != null && item.ProgressColors.Length > 0) ? item.ProgressColors : ctProgress.BackColors, ctProgress.BackColorsGradientAngle, ctProgress.BackColorsPositions))
{
g.FillPath(brush, path);
}
g.Clip = oldClip;
oldClip.Dispose();
}
}
if (ct.BorderColors.Length > 0)
{
for (int i = ct.BorderColors.Length - 1; i > 0; i--)
{
Rectangle rb = item.Bounds;
rb.Inflate(-i, -i);
using (GraphicsPath borderPath = GetPath(item, pointerSize, rb))
{
using (Pen pen = new Pen(ct.BorderColors[i]))
g.DrawPath(pen, borderPath);
}
}
using (Pen pen = new Pen(ct.BorderColors[0]))
g.DrawPath(pen, path);
}
// Render content
r.X += item.Padding.Left;
r.Y += item.Padding.Top;
r.Width -= item.Padding.Horizontal;
r.Height -= item.Padding.Vertical;
if (!item.IsFirst)
{
r.X += pointerSize;
r.Width -= pointerSize;
}
Color textColor = ct.TextColor;
if (!string.IsNullOrEmpty(item.SymbolRealized))
{
Color symbolColor = item.SymbolColor;
if (symbolColor.IsEmpty) symbolColor = textColor;
TextDrawing.DrawStringLegacy(g, item.SymbolRealized, Symbols.GetFont(item.SymbolSize, item.SymbolSet), symbolColor, new Rectangle(r.X, r.Y + r.Height / 2, 0, 0), eTextFormat.Default | eTextFormat.VerticalCenter);
int imageSize = item.ActualSymbolSize.Width + item.ImageTextSpacing;
r.Width -= imageSize;
r.X += imageSize;
}
else if (item.Image != null)
{
g.DrawImage(item.Image, new Rectangle(r.X, r.Y + (r.Height - item.Image.Height) / 2, item.Image.Width, item.Image.Height));
int imageSize = item.Image.Width + item.ImageTextSpacing;
r.Width -= imageSize;
r.X += imageSize;
}
if (!string.IsNullOrEmpty(item.Text))
{
if (!item.TextColor.IsEmpty) textColor = item.TextColor;
Font font = e.ItemPaintArgs.Font;
if (item.TextMarkupBody == null)
{
eTextFormat textFormat = eTextFormat.Default | eTextFormat.VerticalCenter;
if (item.TextAlignment == eButtonTextAlignment.Center)
{
textFormat |= eTextFormat.HorizontalCenter;
if (!item.IsLast)
r.Width -= pointerSize;
}
else if (item.TextAlignment == eButtonTextAlignment.Right)
{
textFormat |= eTextFormat.Right;
if (!item.IsLast)
r.Width -= pointerSize;
}
TextDrawing.DrawString(g, item.Text, font, textColor, r, textFormat);
}
else
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, e.ItemPaintArgs.RightToLeft);
d.HotKeyPrefixVisible = false;
d.ContextObject = item;
Rectangle mr = new Rectangle(r.X, r.Y + (r.Height - item.TextMarkupBody.Bounds.Height) / 2, item.TextMarkupBody.Bounds.Width, item.TextMarkupBody.Bounds.Height);
item.TextMarkupBody.Bounds = mr;
item.TextMarkupBody.Render(d);
}
}
}
private GraphicsPath GetPath(StepItem item, int arrowSize)
{
Rectangle r = item.Bounds;
return GetPath(item, arrowSize, r);
}
private GraphicsPath GetPath(StepItem item, int arrowSize, Rectangle r)
{
r.Width--;
r.Height--;
if (item.IsFirst)
return GetFirstItemPath(r, arrowSize);
else if (item.IsLast)
return GetLastItemPath(r, arrowSize);
else
return GetItemPath(r, arrowSize);
}
private GraphicsPath GetItemPath(Rectangle r, int arrowSize)
{
GraphicsPath path = new GraphicsPath();
path.AddLine(r.X, r.Y, r.X + arrowSize, r.Y + r.Height / 2);
path.AddLine(r.X + arrowSize, r.Y + r.Height / 2, r.X, r.Bottom);
path.AddLine(r.X, r.Bottom, r.Right - arrowSize, r.Bottom);
path.AddLine(r.Right - arrowSize, r.Bottom, r.Right, r.Y + r.Height / 2);
path.AddLine(r.Right, r.Y + r.Height / 2, r.Right - arrowSize, r.Y);
path.CloseAllFigures();
return path;
}
private GraphicsPath GetLastItemPath(Rectangle r, int arrowSize)
{
GraphicsPath path = new GraphicsPath();
ArcData ad = ElementStyleDisplay.GetCornerArc(r, 2, eCornerArc.TopRight);
path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
ad = ElementStyleDisplay.GetCornerArc(r, 2, eCornerArc.BottomRight);
path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
path.AddLine(r.X, r.Bottom, r.X + arrowSize, r.Y + r.Height / 2);
path.AddLine(r.X + arrowSize, r.Y + r.Height / 2, r.X, r.Y);
path.CloseAllFigures();
return path;
}
private GraphicsPath GetFirstItemPath(Rectangle r, int arrowSize)
{
GraphicsPath path = new GraphicsPath();
ArcData ad = ElementStyleDisplay.GetCornerArc(r, 2, eCornerArc.BottomLeft);
path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
ad = ElementStyleDisplay.GetCornerArc(r, 2, eCornerArc.TopLeft);
path.AddArc(ad.X, ad.Y, ad.Width, ad.Height, ad.StartAngle, ad.SweepAngle);
path.AddLine(r.Right - arrowSize, r.Y, r.Right, r.Y + r.Height / 2);
path.AddLine(r.Right, r.Y + r.Height / 2, r.Right - arrowSize, r.Bottom);
path.CloseAllFigures();
return path;
}
#endregion
}
}

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Represents the color table for StepItem single state.
/// </summary>
public class OfficeStepItemStateColorTable
{
/// <summary>
/// Initializes a new instance of the OfficeStepItemStateColorTable class.
/// </summary>
public OfficeStepItemStateColorTable()
{
}
/// <summary>
/// Initializes a new instance of the OfficeStepItemStateColorTable class.
/// </summary>
/// <param name="backColors"></param>
/// <param name="textColor"></param>
/// <param name="borderColors"></param>
public OfficeStepItemStateColorTable(Color[] backColors, Color textColor, Color[] borderColors)
{
BackColors = backColors;
TextColor = textColor;
BorderColors = borderColors;
}
/// <summary>
/// Initializes a new instance of the OfficeStepItemStateColorTable class.
/// </summary>
/// <param name="backColors"></param>
/// <param name="backColorsGradientAngle"></param>
/// <param name="backColorsPositions"></param>
/// <param name="textColor"></param>
/// <param name="borderColors"></param>
public OfficeStepItemStateColorTable(Color[] backColors, int backColorsGradientAngle, float[] backColorsPositions, Color textColor, Color[] borderColors)
{
BackColors = backColors;
BackColorsGradientAngle = backColorsGradientAngle;
BackColorsPositions = backColorsPositions;
TextColor = textColor;
BorderColors = borderColors;
}
/// <summary>
/// Gets or sets the background colors for the step item.
/// </summary>
public Color[] BackColors= new Color[0];
/// <summary>
/// Gets or sets the back colors gradient angle if there is more than one color in BackColors array.
/// </summary>
public int BackColorsGradientAngle = 90;
/// <summary>
/// Gets or sets the gradient colors positions if there is more than one color in BackColors array.
/// </summary>
public float[] BackColorsPositions = new float[0];
/// <summary>
/// Gets or sets the text color for the step item.
/// </summary>
public Color TextColor = Color.Black;
/// <summary>
/// Gets or sets the border colors of the step item.
/// </summary>
public Color[] BorderColors = new Color[0];
}
}

View File

@@ -0,0 +1,304 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the progress steps control.
/// </summary>
[ToolboxBitmap(typeof(ProgressSteps), "ProgressSteps.ico"), ToolboxItem(true), Designer("DevComponents.DotNetBar.Design.ProgressStepsDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf"), System.Runtime.InteropServices.ComVisible(false), DefaultEvent("ItemClick")]
public class ProgressSteps : ItemControl
{
#region Constructor
/// <summary>
/// Initializes a new instance of the ProgressSteps class.
/// </summary>
public ProgressSteps()
: base()
{
_ViewContainer = new StepItemContainer();
_ViewContainer.GlobalItem = false;
_ViewContainer.ContainerControl = this;
_ViewContainer.Displayed = true;
_ViewContainer.Style = eDotNetBarStyle.StyleManagerControlled;
_ViewContainer.SetOwner(this);
this.SetBaseItemContainer(_ViewContainer);
}
private StepItemContainer _ViewContainer = null;
#endregion
#region Implementation
/// <summary>
/// Returns collection of items on a bar.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false)]
public SubItemsCollection Items
{
get
{
return _ViewContainer.SubItems;
}
}
/// <summary>
/// Gets/Sets the visual style for items and color scheme.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Specifies the visual style of the control."), DefaultValue(eDotNetBarStyle.StyleManagerControlled)]
public eDotNetBarStyle Style
{
get
{
return _ViewContainer.Style;
}
set
{
this.ColorScheme.SwitchStyle(value);
_ViewContainer.Style = value;
this.Invalidate();
this.RecalcLayout();
}
}
private Size _PreferredSize = Size.Empty;
[Localizable(true), Browsable(false)]
public new System.Windows.Forms.Padding Padding
{
get { return base.Padding; }
set { base.Padding = value; }
}
public override Size GetPreferredSize(Size proposedSize)
{
if (!_PreferredSize.IsEmpty) return _PreferredSize;
if (!BarFunctions.IsHandleValid(this))
return base.GetPreferredSize(proposedSize);
if (this.Items.Count == 0 || !BarFunctions.IsHandleValid(this) || _ViewContainer.SubItems.Count == 0)
return new Size(base.GetPreferredSize(proposedSize).Width, Dpi.Height22);
int height = GetAutoSizePreferredHeight();
_PreferredSize = new Size(proposedSize.Width, height);
return _PreferredSize;
}
private int GetAutoSizePreferredHeight()
{
int height = ElementStyleLayout.VerticalStyleWhiteSpace(this.GetBackgroundStyle());
height += _ViewContainer.CalculatedHeight > 0 ? _ViewContainer.CalculatedHeight : 20;
return height;
}
protected override void RecalcSize()
{
base.RecalcSize();
if (this.AutoSize && this.IsHandleCreated && GetAutoSizePreferredHeight() != this.Height)
{
InvalidateAutoSize();
this.AdjustSize();
}
}
/// <summary>
/// Gets or sets a value indicating whether the control is automatically resized to display its entire contents. You can set MaximumSize.Width property to set the maximum width used by the control.
/// </summary>
[Browsable(true), DefaultValue(false), EditorBrowsable(EditorBrowsableState.Always), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
if (this.AutoSize != value)
{
base.AutoSize = value;
InvalidateAutoSize();
AdjustSize();
}
}
}
private void InvalidateAutoSize()
{
_PreferredSize = Size.Empty;
}
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
if (this.AutoSize)
{
Size preferredSize = base.PreferredSize;
if (preferredSize.Width > 0)
width = preferredSize.Width;
if (preferredSize.Height > 0)
height = preferredSize.Height;
}
base.SetBoundsCore(x, y, width, height, specified);
}
private void AdjustSize()
{
if (this.AutoSize)
{
System.Drawing.Size prefSize = base.PreferredSize;
if (prefSize.Width > 0 && prefSize.Height > 0)
this.Size = base.PreferredSize;
else if (prefSize.Height > 0)
this.Size = new Size(this.Width, base.PreferredSize.Height);
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Image BackgroundImage
{
get { return base.BackgroundImage; }
set { base.BackgroundImage = value; }
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (this.AutoSize)
this.AdjustSize();
}
/// <summary>
/// Gets or sets the arrow pointer width for the StepItem objects hosted within this container.
/// </summary>
[DefaultValue(10), Category("Appearance"), Description("Gets or sets the arrow pointer width for the StepItem objects hosted within this container.")]
public int PointerSize
{
get { return _ViewContainer.PointerSize; }
set
{
_ViewContainer.PointerSize = value;
}
}
#endregion
#region Property Hiding
[Browsable(false)]
public override eBarImageSize ImageSize
{
get
{
return base.ImageSize;
}
set
{
base.ImageSize = value;
}
}
[Browsable(false)]
public override System.Windows.Forms.ImageList ImagesLarge
{
get
{
return base.ImagesLarge;
}
set
{
base.ImagesLarge = value;
}
}
[Browsable(false)]
public override System.Windows.Forms.ImageList ImagesMedium
{
get
{
return base.ImagesMedium;
}
set
{
base.ImagesMedium = value;
}
}
[Browsable(false)]
public override Font KeyTipsFont
{
get
{
return base.KeyTipsFont;
}
set
{
base.KeyTipsFont = value;
}
}
[Browsable(false)]
public override bool ShowShortcutKeysInToolTips
{
get
{
return base.ShowShortcutKeysInToolTips;
}
set
{
base.ShowShortcutKeysInToolTips = value;
}
}
[Browsable(false)]
public override bool ThemeAware
{
get
{
return base.ThemeAware;
}
set
{
base.ThemeAware = value;
}
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
#endregion
#region Licensing
#if !TRIAL
private string m_LicenseKey = "";
[Browsable(false), DefaultValue("")]
public string LicenseKey
{
get { return m_LicenseKey; }
set
{
if (NativeFunctions.ValidateLicenseKey(value))
return;
m_LicenseKey = (!NativeFunctions.CheckLicenseKey(value) ? "9dsjkhds7" : value);
}
}
#endif
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
#if !TRIAL
if (NativeFunctions.keyValidated2 != 266)
TextDrawing.DrawString(e.Graphics, "Invalid License", this.Font, Color.FromArgb(180, Color.Red), this.ClientRectangle, eTextFormat.Bottom | eTextFormat.HorizontalCenter);
#else
if (NativeFunctions.ColorExpAlt() || !NativeFunctions.CheckedThrough)
{
e.Graphics.Clear(SystemColors.Control);
return;
}
#endif
}
#endregion
}
}

View File

@@ -0,0 +1,845 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents a step item which is used to show single step in multi-step progress control.
/// </summary>
[ToolboxItem(false), DefaultEvent("Click")]
public class StepItem : BaseItem
{
#region Constructor, Copy
/// <summary>
/// Creates new instance of StepItem.
/// </summary>
public StepItem() : this("", "") { }
/// <summary>
/// Creates new instance of StepItem and assigns the name to it.
/// </summary>
/// <param name="sItemName">Item name.</param>
public StepItem(string sItemName) : this(sItemName, "") { }
/// <summary>
/// Creates new instance of StepItem and assigns the name and text to it.
/// </summary>
/// <param name="sItemName">Item name.</param>
/// <param name="ItemText">item text.</param>
public StepItem(string sItemName, string ItemText)
: base(sItemName, ItemText)
{
//this.ClickRepeatInterval = 200;
this.MouseUpNotification = true;
//this.MouseDownCapture = true;
_Padding.PropertyChanged += PaddingPropertyChanged;
}
/// <summary>
/// Returns copy of the item.
/// </summary>
public override BaseItem Copy()
{
StepItem objCopy = new StepItem(m_Name);
this.CopyToItem(objCopy);
return objCopy;
}
/// <summary>
/// Copies the StepItem specific properties to new instance of the item.
/// </summary>
/// <param name="copy">New StepItem instance.</param>
internal void InternalCopyToItem(StepItem copy)
{
CopyToItem(copy);
}
/// <summary>
/// Copies the StepItem specific properties to new instance of the item.
/// </summary>
/// <param name="copy">New StepItem instance.</param>
protected override void CopyToItem(BaseItem copy)
{
StepItem c = copy as StepItem;
c.Symbol = _Symbol;
c.SymbolSet = _SymbolSet;
c.SymbolColor = _SymbolColor;
c.SymbolSize = _SymbolSize;
base.CopyToItem(c);
}
protected override void Dispose(bool disposing)
{
if (_ItemPath != null)
{
_ItemPath.Dispose();
_ItemPath = null;
}
base.Dispose(disposing);
}
#endregion
#region Internal Implementation
public override void Paint(ItemPaintArgs p)
{
Rendering.BaseRenderer renderer = p.Renderer;
if (renderer != null)
{
StepItemRendererEventArgs e = new StepItemRendererEventArgs(this, p.Graphics);
e.ItemPaintArgs = p;
renderer.DrawStepItem(e);
}
else
{
Rendering.StepItemPainter painter = PainterFactory.CreateStepItemPainter(this);
if (painter != null)
{
StepItemRendererEventArgs e = new StepItemRendererEventArgs(this, p.Graphics);
e.ItemPaintArgs = p;
painter.Paint(e);
}
}
if (this.DesignMode && this.Focused)
{
Rectangle r = Rectangle.Round(_ItemPath.GetBounds());
r.Inflate(-1, -1);
DesignTime.DrawDesignTimeSelection(p.Graphics, r, p.Colors.ItemDesignTimeBorder);
}
this.DrawInsertMarker(p.Graphics);
}
public override void RecalcSize()
{
Font font = GetFont(null);
Size size = Size.Empty;
Control objCtrl = this.ContainerControl as Control;
if (objCtrl == null || objCtrl.Disposing || objCtrl.IsDisposed)
return;
Graphics g = BarFunctions.CreateGraphics(objCtrl);
if (g == null) return;
try
{
if (!string.IsNullOrEmpty(_Symbol))
{
_ActualSymbolSize = GetSymbolSize(g);
size = _ActualSymbolSize;
}
else if (_Image != null)
{
size = _Image.Size;
}
if (!string.IsNullOrEmpty(this.Text))
{
Size textSize = ButtonItemLayout.MeasureItemText(this, g, 0, objCtrl.Font, eTextFormat.Default, objCtrl.RightToLeft == RightToLeft.Yes);
size.Width += textSize.Width;
size.Height = Math.Max(size.Height, textSize.Height);
if (_Image != null || !string.IsNullOrEmpty(_Symbol))
size.Width += Dpi.Width(_ImageTextSpacing);
}
else if (string.IsNullOrEmpty(_Symbol) && _Image == null)
size = new System.Drawing.Size(Dpi.Width16, Dpi.Height16);
size.Width += GetPointerSize();
if(!_IsFirst && !_IsLast)
size.Width += Dpi.Width(GetPointerSize());
size.Width += Dpi.Width(_Padding.Horizontal);
size.Height += Dpi.Height(_Padding.Vertical);
base.RecalcSize();
}
finally
{
g.Dispose();
}
if (!_MinimumSize.IsEmpty)
{
if (size.Width < _MinimumSize.Width) size.Width = _MinimumSize.Width;
if (size.Height < _MinimumSize.Height) size.Height = _MinimumSize.Height;
}
m_Rect.Size = size;
}
internal int GetPointerSize()
{
if (this.Parent is StepItemContainer)
return ((StepItemContainer)this.Parent).PointerSize;
return 10;
}
private Size GetSymbolSize(Graphics g)
{
Size symbolSize = Size.Empty;
if (g == null || string.IsNullOrEmpty(_Symbol)) return symbolSize;
Font symFont = Symbols.GetFont(this.SymbolSize, this.SymbolSet);
symbolSize = TextDrawing.MeasureString(g, "\uF00A", symFont); // Need to do this to get consistent size for the symbol since they are not all the same width we pick widest
int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) *
symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style)));
symbolSize.Height -= descent;
return symbolSize;
}
private Size _ActualSymbolSize = Size.Empty;
internal Size ActualSymbolSize
{
get
{
return _ActualSymbolSize;
}
}
/// <summary>
/// Returns the Font object to be used for drawing the item text.
/// </summary>
/// <returns>Font object.</returns>
private Font GetFont(ItemPaintArgs pa)
{
System.Drawing.Font font = null;
if (pa != null)
font = pa.Font;
if (font == null)
{
System.Windows.Forms.Control objCtrl = null;
if (pa != null)
objCtrl = pa.ContainerControl;
if (objCtrl == null)
objCtrl = this.ContainerControl as System.Windows.Forms.Control;
if (objCtrl != null && objCtrl.Font != null)
font = (Font)objCtrl.Font;
else
font = SystemFonts.DefaultFont; // (Font)System.Windows.Forms.SystemInformation.MenuFont;
}
return font;
}
private GraphicsPath _ItemPath = null;
/// <summary>
/// Gets the render path of the item.
/// </summary>
[Browsable(false)]
public GraphicsPath ItemPath
{
get { return _ItemPath; }
internal set
{
if (_ItemPath != null)
_ItemPath.Dispose();
_ItemPath = value;
}
}
private bool _IsFirst;
private int _Minimum = 0;
/// <summary>
/// Gets or sets the minimum value of the range of the control.
/// </summary>
[Browsable(true), Description("Gets or sets the minimum value of the range of the control."), Category("Behavior"), DefaultValue(0)]
public int Minimum
{
get { return _Minimum; }
set
{
if (value != _Minimum)
{
int oldValue = _Minimum;
_Minimum = value;
OnMinimumChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Minimum property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnMinimumChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("Minimum"));
this.OnAppearanceChanged();
this.Refresh();
}
private int _Maximum = 100;
[Browsable(true), Description("Gets or sets the maximum value of the range of the control."), Category("Behavior"), DefaultValue(100)]
public int Maximum
{
get { return _Maximum; }
set
{
if (value != _Maximum)
{
int oldValue = _Maximum;
_Maximum = value;
OnMaximumChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Maximum property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnMaximumChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("Maximum"));
this.OnAppearanceChanged();
this.Refresh();
}
private int _Value = 0;
[Browsable(true), Description("Gets or sets the current position of the progress bar."), Category("Behavior"), DefaultValue(0)]
public int Value
{
get { return _Value; }
set
{
if (value != _Value)
{
int oldValue = _Value;
_Value = value;
OnValueChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Value property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnValueChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("Value"));
this.OnAppearanceChanged();
this.Refresh();
}
private Color _SymbolColor = Color.Empty;
/// <summary>
/// Gets or sets the color of the Symbol.
/// </summary>
[Category("Appearance"), Description("Indicates color of the Symbol.")]
public Color SymbolColor
{
get { return _SymbolColor; }
set { _SymbolColor = value; this.Refresh(); }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSymbolColor()
{
return !_SymbolColor.IsEmpty;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSymbolColor()
{
this.SymbolColor = Color.Empty;
}
/// <summary>
/// Gets the realized symbol string.
/// </summary>
[Browsable(false)]
public string SymbolRealized
{
get { return _SymbolRealized; }
}
private string _Symbol = "", _SymbolRealized = "";
/// <summary>
/// Indicates the symbol displayed on face of the button instead of the image. Setting the symbol overrides the image setting.
/// </summary>
[DefaultValue(""), Category("Appearance"), Description("Indicates the symbol displayed on face of the button instead of the image. Setting the symbol overrides the image setting.")]
[Editor("DevComponents.DotNetBar.Design.SymbolTypeEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
public string Symbol
{
get { return _Symbol; }
set
{
if (value != _Symbol)
{
string oldValue = _Symbol;
_Symbol = value;
OnSymbolChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Symbol property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnSymbolChanged(string oldValue, string newValue)
{
if (string.IsNullOrEmpty(newValue))
_SymbolRealized = "";
else
_SymbolRealized = Symbols.GetSymbol(newValue);
//OnPropertyChanged(new PropertyChangedEventArgs("Symbol"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private eSymbolSet _SymbolSet = eSymbolSet.Awesome;
/// <summary>
/// Gets or sets the symbol set used to represent the Symbol.
/// </summary>
[Browsable(false), DefaultValue(eSymbolSet.Awesome)]
public eSymbolSet SymbolSet
{
get { return _SymbolSet; }
set
{
if (_SymbolSet != value)
{
eSymbolSet oldValue = _SymbolSet;
_SymbolSet = value;
OnSymbolSetChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when SymbolSet property value changes.
/// </summary>
/// <param name="oldValue">Indciates old value</param>
/// <param name="newValue">Indicates new value</param>
protected virtual void OnSymbolSetChanged(eSymbolSet oldValue, eSymbolSet newValue)
{
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private float _SymbolSize = 13f;
/// <summary>
/// Indicates the size of the symbol in points.
/// </summary>
[DefaultValue(12f), Category("Appearance"), Description("Indicates the size of the symbol in points.")]
public float SymbolSize
{
get { return _SymbolSize; }
set
{
if (value != _SymbolSize)
{
float oldValue = _SymbolSize;
_SymbolSize = value;
OnSymbolSizeChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when SymbolSize property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnSymbolSizeChanged(float oldValue, float newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("SymbolSize"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private Image _Image = null;
/// <summary>
/// Indicates the image that is displayed next to the item text label.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates the image that is displayed next to the item text label.")]
public Image Image
{
get { return _Image; }
set
{
if (value != _Image)
{
Image oldValue = _Image;
_Image = value;
OnImageChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when Image property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnImageChanged(Image oldValue, Image newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("Image"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
/// <summary>
/// Gets or sets whether this is first item in StepControl.
/// </summary>
internal bool IsFirst
{
get { return _IsFirst; }
set
{
_IsFirst = value;
}
}
private bool _IsLast = false;
/// <summary>
/// Gets or sets whether this is laste item in StepControl.
/// </summary>
internal bool IsLast
{
get { return _IsLast; }
set
{
_IsLast = value;
}
}
private Size _MinimumSize = Size.Empty;
/// <summary>
/// Indicates minimum size of the item
/// </summary>
[Category("Appearance"), Description("Indicates minimum size of the item")]
public Size MinimumSize
{
get { return _MinimumSize; }
set
{
if (value != _MinimumSize)
{
Size oldValue = _MinimumSize;
_MinimumSize = value;
OnMinimumSizeChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when MinimumSize property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnMinimumSizeChanged(Size oldValue, Size newValue)
{
// OnPropertyChanged(new PropertyChangedEventArgs("MinimumSize"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeMinimumSize()
{
return !_MinimumSize.IsEmpty;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetMinimumSize()
{
this.Size = Size.Empty;
}
private bool _HotTracking = true;
/// <summary>
/// Specifies whether item changes its appearance when mouse is moved over the item
/// </summary>
[DefaultValue(true), Category("Behavior"), Description("Specifies whether item changes its appearance when mouse is moved over the item")]
public bool HotTracking
{
get { return _HotTracking; }
set
{
if (value != _HotTracking)
{
bool oldValue = _HotTracking;
_HotTracking = value;
OnHotTrackingChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when HotTracking property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnHotTrackingChanged(bool oldValue, bool newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("HotTracking"));
}
private bool _MouseOver = false, _MouseDown = false;
public override void InternalMouseEnter()
{
base.InternalMouseEnter();
if (!this.DesignMode)
{
_MouseOver = true;
if (this.GetEnabled() && _HotTracking)
this.Refresh();
}
}
public override void InternalMouseLeave()
{
base.InternalMouseLeave();
if (!this.DesignMode)
{
_MouseOver = false;
_MouseDown = false;
if (this.GetEnabled() && _HotTracking)
this.Refresh();
}
}
public override void InternalMouseDown(MouseEventArgs objArg)
{
base.InternalMouseDown(objArg);
if (objArg.Button == MouseButtons.Left && !this.DesignMode)
{
_MouseDown = true;
if (this.GetEnabled() && _HotTracking)
this.Refresh();
}
}
public override void InternalMouseUp(MouseEventArgs objArg)
{
base.InternalMouseUp(objArg);
if (_MouseDown && !this.DesignMode)
{
_MouseDown = false;
if (this.GetEnabled() && _HotTracking)
this.Refresh();
}
}
/// <summary>
/// Gets whether mouse is over the item.
/// </summary>
[Browsable(false)]
public bool IsMouseOver
{
get { return _MouseOver; }
internal set { _MouseOver = value; }
}
/// <summary>
/// Gets whether left mouse button is pressed on the item.
/// </summary>
[Browsable(false)]
public bool IsMouseDown
{
get { return _MouseDown; }
internal set { _MouseDown = value; }
}
private int _ImageTextSpacing = 4;
/// <summary>
/// Indicates the spacing between image and text.
/// </summary>
[DefaultValue(4), Category("Appearance"), Description("Indicates the spacing between image and text.")]
public int ImageTextSpacing
{
get { return _ImageTextSpacing; }
set
{
if (value != _ImageTextSpacing)
{
int oldValue = _ImageTextSpacing;
_ImageTextSpacing = value;
OnImageTextSpacingChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when ImageTextSpacing property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnImageTextSpacingChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("ImageTextSpacing"));
NeedRecalcSize = true;
OnAppearanceChanged();
this.Refresh();
}
private const int DefaultPadding = 4;
private Padding _Padding = new Padding(DefaultPadding);
/// <summary>
/// Gets or sets padding around content of the item.
/// </summary>
[Browsable(true), Category("Appearance"), Description("Gets or sets padding around content of the item."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Padding Padding
{
get { return _Padding; }
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializePadding()
{
return _Padding.Bottom != DefaultPadding || _Padding.Top != DefaultPadding || _Padding.Left != DefaultPadding || _Padding.Right != DefaultPadding;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetPadding()
{
_Padding.All = DefaultPadding;
}
private void PaddingPropertyChanged(object sender, PropertyChangedEventArgs e)
{
NeedRecalcSize = true;
this.Refresh();
}
private Color[] _ProgressColors = null;
/// <summary>
/// Indicates the array of colors that when set are used to draw the current progress, i.e. Value>Minimum
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates the array of colors that when set are used to draw the current progress, i.e. Value>Minimum"), TypeConverter(typeof(ArrayConverter))]
public Color[] ProgressColors
{
get
{
return _ProgressColors;
}
set
{
if (_ProgressColors != value)
{
_ProgressColors = value;
//OnPropertyChanged(new PropertyChangedEventArgs("Colors"));
this.Refresh();
}
}
}
private Color[] _BackColors = null;
/// <summary>
/// Indicates the array of colors that when set are used to draw the background of the item.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates the array of colors that when set are used to draw the background of the item."), TypeConverter(typeof(ArrayConverter))]
public Color[] BackColors
{
get
{
return _BackColors;
}
set
{
if (_BackColors != value)
{
_BackColors = value;
//OnPropertyChanged(new PropertyChangedEventArgs("Colors"));
this.Refresh();
}
}
}
private eButtonTextAlignment _TextAlignment = eButtonTextAlignment.Left;
/// <summary>
/// Gets or sets the text alignment. Default value is left.
/// </summary>
[Browsable(true), DefaultValue(eButtonTextAlignment.Left), Category("Appearance"), Description("Indicates text alignment.")]
public eButtonTextAlignment TextAlignment
{
get { return _TextAlignment; }
set
{
_TextAlignment = value;
this.Refresh();
}
}
/// <summary>
/// Gets or sets the text associated with this item.
/// </summary>
[System.ComponentModel.Browsable(true), DevCoBrowsable(true), Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor)), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("The text contained in the item."), System.ComponentModel.Localizable(true), System.ComponentModel.DefaultValue("")]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
private Color _TextColor = Color.Empty;
/// <summary>
/// Gets or sets the color of the text.
/// </summary>
[Category("Columns"), Description("Indicates color of text.")]
public Color TextColor
{
get { return _TextColor; }
set { _TextColor = value; this.Refresh(); }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTextColor()
{
return !_TextColor.IsEmpty;
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTextColor()
{
this.TextColor = Color.Empty;
}
#endregion
#region Markup Implementation
/// <summary>
/// Gets whether item supports text markup. Default is false.
/// </summary>
protected override bool IsMarkupSupported
{
get { return _EnableMarkup; }
}
private bool _EnableMarkup = true;
/// <summary>
/// Gets or sets whether text-markup support is enabled for items Text property. Default value is true.
/// Set this property to false to display HTML or other markup in the item instead of it being parsed as text-markup.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether text-markup support is enabled for items Text property.")]
public bool EnableMarkup
{
get { return _EnableMarkup; }
set
{
if (_EnableMarkup != value)
{
_EnableMarkup = value;
NeedRecalcSize = true;
OnTextChanged();
}
}
}
#endregion
}
}

Some files were not shown because too many files have changed in this diff Show More