System.Windows.Forms.TabControl.OnDrawItemInternal C# (CSharp) Method

OnDrawItemInternal() private method

private OnDrawItemInternal ( DrawItemEventArgs e ) : void
e DrawItemEventArgs
return void
		internal void OnDrawItemInternal (DrawItemEventArgs e)
		{
			OnDrawItem (e);
		}

Usage Example

Example #1
0
        protected virtual int DrawTab(Graphics dc, System.Windows.Forms.TabPage page, System.Windows.Forms.TabControl tab, Rectangle_ bounds, bool is_selected)
        {
            Rectangle_ interior;
            int        res = bounds.Width;

            dc.FillRectangle(ResPool.GetSolidBrush(tab.BackColor), bounds);

            if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons)
            {
                // Separators
                if (tab.Appearance == TabAppearance.FlatButtons)
                {
                    int width = bounds.Width;
                    bounds.Width += (flatButtonSpacing - 2);
                    res           = bounds.Width;
                    if (tab.Alignment == TabAlignment.Top || tab.Alignment == TabAlignment.Bottom)
                    {
                        ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
                    }
                    else
                    {
                        ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Etched, Border3DSide.Top);
                    }
                    bounds.Width = width;
                }

                if (is_selected)
                {
                    ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                }
                else if (tab.Appearance != TabAppearance.FlatButtons)
                {
                    ThemeEngine.Current.CPDrawBorder3D(dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                }
            }
            else
            {
                CPColor cpcolor = ResPool.GetCPColor(tab.BackColor);

                Pen light = ResPool.GetPen(cpcolor.LightLight);

                switch (tab.Alignment)
                {
                case TabAlignment.Top:

                    dc.DrawLine(light, bounds.Left, bounds.Bottom - 1, bounds.Left, bounds.Top + 3);
                    dc.DrawLine(light, bounds.Left, bounds.Top + 3, bounds.Left + 2, bounds.Top);
                    dc.DrawLine(light, bounds.Left + 2, bounds.Top, bounds.Right - 3, bounds.Top);

                    dc.DrawLine(SystemPens.ControlDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 2, bounds.Bottom - 1);
                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 2);
                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 1);
                    break;

                case TabAlignment.Bottom:

                    dc.DrawLine(light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 2);
                    dc.DrawLine(light, bounds.Left, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);

                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
                    dc.DrawLine(SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);

                    dc.DrawLine(SystemPens.ControlDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Top + 1);
                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 2);
                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Top + 1);

                    break;

                case TabAlignment.Left:

                    dc.DrawLine(light, bounds.Left - 2, bounds.Top, bounds.Right, bounds.Top);
                    dc.DrawLine(light, bounds.Left, bounds.Top + 2, bounds.Left - 2, bounds.Top);
                    dc.DrawLine(light, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);

                    dc.DrawLine(SystemPens.ControlDark, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom - 1);

                    dc.DrawLine(SystemPens.ControlDark, bounds.Left + 2, bounds.Bottom - 1, bounds.Right, bounds.Bottom - 1);
                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Right, bounds.Bottom);

                    break;

                default:                         // TabAlignment.Right

                    dc.DrawLine(light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
                    dc.DrawLine(light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);

                    dc.DrawLine(SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
                    dc.DrawLine(SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);

                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
                    dc.DrawLine(SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);

                    break;
                }
            }

            Point_ padding = tab.Padding;

            interior = new Rectangle_(bounds.Left + padding.X - 1,              // substract a little offset
                                      bounds.Top + padding.Y,
                                      bounds.Width - (padding.X * 2),
                                      bounds.Height - (padding.Y * 2));

            if (tab.DrawMode == TabDrawMode.Normal && page.Text != null)
            {
                if (tab.Alignment == TabAlignment.Left)
                {
                    dc.TranslateTransform(bounds.Left, bounds.Bottom);
                    dc.RotateTransform(-90);
                    dc.DrawString(page.Text, tab.Font,
                                  SystemBrushes.ControlText,
                                  tab.Padding.X - 2,               // drawstring adds some extra unwanted leading spaces, so trimming
                                  tab.Padding.Y,
                                  defaultFormatting);
                    dc.ResetTransform();
                }
                else if (tab.Alignment == TabAlignment.Right)
                {
                    dc.TranslateTransform(bounds.Right, bounds.Top);
                    dc.RotateTransform(90);
                    dc.DrawString(page.Text, tab.Font,
                                  SystemBrushes.ControlText,
                                  tab.Padding.X - 2,               // drawstring adds some extra unwanted leading spaces, so trimming
                                  tab.Padding.Y,
                                  defaultFormatting);
                    dc.ResetTransform();
                }
                else
                {
                    Rectangle_ str_rect = interior;

                    if (is_selected)
                    {
                        // Reduce the interior Size_ to match the inner Size_ of non-selected tabs
                        str_rect.X      += selectedTabDelta.X;
                        str_rect.Y      += selectedTabDelta.Y;
                        str_rect.Width  -= selectedTabDelta.Width;
                        str_rect.Height -= selectedTabDelta.Height;

                        str_rect.Y -= selectedTabDelta.Y;                         // Move up the text / image of the selected tab
                    }

                    if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count)
                    {
                        int image_x;
                        if (tab.SizeMode != TabSizeMode.Fixed)
                        {
                            image_x = str_rect.X;
                        }
                        else
                        {
                            image_x = str_rect.X + (str_rect.Width - tab.ImageList.ImageSize.Width) / 2;
                            if (page.Text != null)
                            {
                                SizeF_ textSize = dc.MeasureString(page.Text, page.Font, str_rect.Size);
                                image_x -= (int)(textSize.Width / 2);
                            }
                        }
                        int image_y = str_rect.Y + (str_rect.Height - tab.ImageList.ImageSize.Height) / 2;
                        tab.ImageList.Draw(dc, new Point_(image_x, image_y), page.ImageIndex);
                        str_rect.X     += tab.ImageList.ImageSize.Width + 2;
                        str_rect.Width -= tab.ImageList.ImageSize.Width + 2;
                    }
                    dc.DrawString(page.Text, tab.Font,
                                  SystemBrushes.ControlText,
                                  str_rect,
                                  defaultFormatting);
                }
            }
            else if (page.Text != null)
            {
                DrawItemState state = DrawItemState.None;
                if (page == tab.SelectedTab)
                {
                    state |= DrawItemState.Selected;
                }
                DrawItemEventArgs e = new DrawItemEventArgs(dc,
                                                            tab.Font, bounds, tab.IndexForTabPage(page),
                                                            state, page.ForeColor, page.BackColor);
                tab.OnDrawItemInternal(e);
                return(res);
            }

            // TabControl ignores the value of ShowFocusCues
            if (page.Parent.Focused && is_selected)
            {
                Rectangle_ focus_rect = bounds;
                focus_rect.Inflate(-2, -2);
                ThemeEngine.Current.CPDrawFocusRectangle(dc, focus_rect, tab.BackColor, tab.ForeColor);
            }

            return(res);
        }
All Usage Examples Of System.Windows.Forms.TabControl::OnDrawItemInternal