using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace AeroWizard { /// /// Wizard control that shows a step summary on the left of the wizard page area. /// [ProvideProperty("StepText", typeof(WizardPage))] [ProvideProperty("StepTextIndentLevel", typeof(WizardPage))] [ToolboxItem(true), ToolboxBitmap(typeof(StepWizardControl), "StepWizardControl.bmp")] public class StepWizardControl : WizardControl, IExtenderProvider { private StepList list; private Splitter splitter; /// /// Initializes a new instance of the class. /// public StepWizardControl() { var ds = RightToLeft == System.Windows.Forms.RightToLeft.Yes ? DockStyle.Right : DockStyle.Left; pageContainer.Controls.Add(splitter = new Splitter() { Dock = ds, BorderStyle = BorderStyle.FixedSingle, Width = 1, Name = "splitter" }); pageContainer.Controls.Add(list = new StepList() { Dock = ds, Name = "stepList" }); list.DrawItem += list_DrawItem; list.MeasureItem += list_MeasureItem; Pages.Reset += Pages_Reset; } /// /// Occurs when a visual aspect of an owner-drawn StepList changes. /// [Category("Appearance")] public event EventHandler DrawStepListItem; /// /// Occurs when an owner-drawn StepList is created and the sizes of the list items are determined. /// [Category("Appearance")] public event EventHandler MeasureStepListItem; /// /// Gets or sets a value indicating whether the StepWizardControl step list is drawn by the operating system or by code that you provide. /// /// /// true if the StepWizardControl step list is drawn by code that you provide; otherwise, false. /// [DefaultValue(false), Category("Appearance"), Description("Indicates if step list items are drawn by owner.")] public bool OwnerDrawStepList { get { return list.OwnerDraw; } set { list.OwnerDraw = value; } } /// /// Gets or sets the StepList font. /// /// /// The StepList font. /// [Category("Appearance"), Description("Font for drawing StepList.")] public Font StepListFont { get { return list.Font; } set { list.Font = value; } } /// /// Gets or sets the width of the step list. /// /// /// The width of the step list. /// [DefaultValue(150), Category("Appearance"), Description("Determines width of step list on left.")] public int StepListWidth { get { return list.Width; } set { list.Width = value; } } /// /// Gets the step text. /// /// The page. /// Step text for the specified wizard page. [DefaultValue((string)null), Category("Appearance"), Description("Alternate text to provide to the StepList. Default value comes the Text property of the WizardPage.")] public string GetStepText(WizardPage page) => list.GetStepText(page); /// /// Gets the step text indent level. /// /// The page. /// Step text indent level for the specified wizard page. [DefaultValue(0), Category("Appearance"), Description("Indentation level for text provided to the StepList.")] public int GetStepTextIndentLevel(WizardPage page) => list.GetStepTextIndentLevel(page); /// /// Specifies whether this object can provide its extender properties to the specified object. /// /// The to receive the extender properties. /// /// true if this object can provide extender properties to the specified object; otherwise, false. /// bool IExtenderProvider.CanExtend(object extendee) => (extendee is WizardPage); /// /// Sets the step text. /// /// The page. /// The value. public void SetStepText(WizardPage page, string value) { list.SetStepText(page, value); } /// /// Sets the step text indent level. /// /// The page. /// The indent level. public void SetStepTextIndentLevel(WizardPage page, int value) { list.SetStepTextIndentLevel(page, value); } /// /// Raises the event. /// /// The instance containing the event data. protected virtual void OnDrawStepListItem(DrawStepListItemEventArgs e) { var h = DrawStepListItem; if (h != null) h(this, e); } /// /// Raises the event. /// /// The instance containing the event data. protected virtual void OnMeasureStepListItem(MeasureStepListItemEventArgs e) { var h = MeasureStepListItem; if (h != null) h(this, e); } /// /// Raises the event. /// /// An that contains the event data. protected override void OnRightToLeftChanged(System.EventArgs e) { base.OnRightToLeftChanged(e); var ds = RightToLeft == System.Windows.Forms.RightToLeft.Yes ? DockStyle.Right : DockStyle.Left; if (pageContainer.Controls.Count > 1) { pageContainer.Controls["splitter"].Dock = ds; pageContainer.Controls["stepList"].Dock = ds; } } private void list_DrawItem(object sender, DrawStepListItemEventArgs e) { OnDrawStepListItem(e); } private void list_MeasureItem(object sender, MeasureStepListItemEventArgs e) { OnMeasureStepListItem(e); } void Pages_Reset(object sender, System.Collections.Generic.EventedList.ListChangedEventArgs e) { pageContainer.Controls.Add(splitter); pageContainer.Controls.Add(list); } private void ResetStepListFont() { list.Font = Font; } private void ResetStepText(WizardPage page) { SetStepText(page, null); } private bool ShouldSerializeStepListFont() => Font != list.Font; private bool ShouldSerializeStepText(WizardPage page) => (GetStepText(page) != page.Text); } /// /// Provides data for the event. /// public class DrawStepListItemEventArgs : EventArgs { internal DrawStepListItemEventArgs(Graphics graphics, Font font, Rectangle itemRect, WizardPage page, bool isSelected, bool isCompleted) { Graphics = graphics; Font = font; Bounds = itemRect; Item = page; Selected = isSelected; Completed = isCompleted; } /// /// Gets the size and location of the item to draw. /// /// /// A rectangle that represents the bounds of the item to draw. /// public Rectangle Bounds { get; } /// /// Gets a value indicating whether this step has already been completed. /// /// /// true if completed; otherwise, false. /// public bool Completed { get; } /// /// Gets the used to draw the item. /// /// /// The used to draw the item. /// public Font Font { get; } /// /// Gets the used to draw the item. /// /// /// The used to draw the item. /// public Graphics Graphics { get; } /// /// Gets the to which this item refers. /// /// /// The to which this item refers. /// public WizardPage Item { get; } /// /// Gets a value indicating whether this item is the one currently selected. /// /// /// true if selected; otherwise, false. /// public bool Selected { get; } } /// /// Provides data for the event. /// public class MeasureStepListItemEventArgs : EventArgs { internal MeasureStepListItemEventArgs(Graphics graphics, Font font, WizardPage page, Size itemSize) { Graphics = graphics; Font = font; Item = page; ItemSize = itemSize; } /// /// Gets the used to draw the item. /// /// /// The used to draw the item. /// public Font Font { get; } /// /// Gets the used to draw the item. /// /// /// The used to draw the item. /// public Graphics Graphics { get; } /// /// Gets the to which this item refers. /// /// /// The to which this item refers. /// public WizardPage Item { get; } /// /// Gets or sets the size of the item. /// /// /// The size of the item. /// public Size ItemSize { get; set; } } }