Beispiel #1
0
        /// <summary>
        /// Provides custom drawing to the wizard page.
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            // raise paint event
            base.OnPaint(e);

            // check if custom style
            if (this.style == WizardPageStyle.Custom)
            {
                // filter out
                return;
            }

            // init graphic resources
            Rectangle headerRect      = this.ClientRectangle;
            Rectangle glyphRect       = Rectangle.Empty;
            Rectangle titleRect       = Rectangle.Empty;
            Rectangle descriptionRect = Rectangle.Empty;

            // determine text format
            StringFormat textFormat = StringFormat.GenericDefault;

            textFormat.LineAlignment = StringAlignment.Near;
            textFormat.Alignment     = StringAlignment.Near;
            textFormat.Trimming      = StringTrimming.EllipsisCharacter;

            Wizard parentWizard = ParentWizard;

            switch (this.style)
            {
            case WizardPageStyle.Standard:
                // adjust height for header
                headerRect.Height = HEADER_AREA_HEIGHT;
                // draw header border
                ControlPaint.DrawBorder3D(e.Graphics, headerRect, Border3DStyle.Etched, Border3DSide.Bottom);
                // adjust header rect not to overwrite the border
                headerRect.Height -= SystemInformation.Border3DSize.Height;
                // fill header with window color
                e.Graphics.FillRectangle(SystemBrushes.Window, headerRect);

                // determine header image regtangle
                int headerPadding = (int)Math.Floor((double)(HEADER_AREA_HEIGHT - HEADER_GLYPH_SIZE) / 2);
                glyphRect.Location = new Point(this.Width - HEADER_GLYPH_SIZE - headerPadding, headerPadding);
                glyphRect.Size     = new Size(HEADER_GLYPH_SIZE, HEADER_GLYPH_SIZE);

                // determine the header content
                Image headerImage     = null;
                Font  headerFont      = this.Font;
                Font  headerTitleFont = this.Font;
                if (parentWizard != null)
                {
                    // get content from parent wizard, if exists
                    headerImage     = parentWizard.HeaderImage;
                    headerFont      = parentWizard.HeaderFont;
                    headerTitleFont = parentWizard.HeaderTitleFont;
                }

                // check if we have an image
                if (headerImage == null)
                {
                    if (ShowGlyphPlaceHolder)
                    {
                        // display a focus rect as a place holder
                        ControlPaint.DrawFocusRectangle(e.Graphics, glyphRect);
                    }
                }
                else
                {
                    // draw header image
                    e.Graphics.DrawImage(headerImage, glyphRect);
                }

                // determine title height
                int headerTitleHeight = (int)Math.Ceiling(e.Graphics.MeasureString(this.title, headerTitleFont, 0, textFormat).Height);

                // calculate text sizes
                titleRect.Location = new Point(HEADER_TEXT_PADDING,
                                               HEADER_TEXT_PADDING);
                titleRect.Size = new Size(glyphRect.Left - HEADER_TEXT_PADDING,
                                          headerTitleHeight);
                descriptionRect.Location = titleRect.Location;
                descriptionRect.Y       += headerTitleHeight + HEADER_TEXT_PADDING / 2;
                descriptionRect.Size     = new Size(titleRect.Width,
                                                    HEADER_AREA_HEIGHT - descriptionRect.Y);

                // draw tilte text (single line, truncated with ellipsis)
                e.Graphics.DrawString(this.title,
                                      headerTitleFont,
                                      SystemBrushes.WindowText,
                                      titleRect,
                                      textFormat);
                // draw description text (multiple lines if needed)
                e.Graphics.DrawString(this.description,
                                      headerFont,
                                      SystemBrushes.WindowText,
                                      descriptionRect,
                                      textFormat);
                break;

            case WizardPageStyle.Welcome:
            case WizardPageStyle.Finish:
                // fill whole page with window color
                e.Graphics.FillRectangle(SystemBrushes.Window, headerRect);

                // determine welcome image regtangle
                glyphRect.Location = Point.Empty;
                glyphRect.Size     = new Size(WELCOME_GLYPH_WIDTH, this.Height);

                // determine the icon that should appear on the welcome page
                Image welcomeImage     = null;
                Font  welcomeFont      = this.Font;
                Font  welcomeTitleFont = this.Font;
                if (ParentWizard != null)
                {
                    // get content from parent wizard, if exists
                    welcomeImage     = parentWizard.WelcomeImage;
                    welcomeFont      = parentWizard.WelcomeFont;
                    welcomeTitleFont = parentWizard.WelcomeTitleFont;
                }

                // check if we have an image
                if (welcomeImage == null)
                {
                    if (ShowGlyphPlaceHolder)
                    {
                        // display a focus rect as a place holder
                        ControlPaint.DrawFocusRectangle(e.Graphics, glyphRect);
                    }
                }
                else
                {
                    // draw welcome page image
                    e.Graphics.DrawImage(welcomeImage, glyphRect);
                }

                // calculate text sizes
                titleRect.Location = new Point(WELCOME_GLYPH_WIDTH + HEADER_TEXT_PADDING,
                                               HEADER_TEXT_PADDING);
                titleRect.Width = this.Width - titleRect.Left - HEADER_TEXT_PADDING;
                // determine title height
                int welcomeTitleHeight = (int)Math.Ceiling(e.Graphics.MeasureString(this.title, welcomeTitleFont, titleRect.Width, textFormat).Height);
                descriptionRect.Location = titleRect.Location;
                descriptionRect.Y       += welcomeTitleHeight + HEADER_TEXT_PADDING;
                descriptionRect.Size     = new Size(this.Width - descriptionRect.Left - HEADER_TEXT_PADDING,
                                                    this.Height - descriptionRect.Y);

                // draw tilte text (multiple lines if needed)
                e.Graphics.DrawString(this.title,
                                      welcomeTitleFont,
                                      SystemBrushes.WindowText,
                                      titleRect,
                                      textFormat);
                // draw description text (multiple lines if needed)
                e.Graphics.DrawString(this.description,
                                      welcomeFont,
                                      SystemBrushes.WindowText,
                                      descriptionRect,
                                      textFormat);
                break;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="WizardPagesCollection"/> class.
 /// </summary>
 /// <param name="owner">A Wizard object that owns the collection.</param>
 internal WizardPagesCollection(Wizard owner)
 {
     this.owner = owner;
 }