IndexForTabPage() private method

private IndexForTabPage ( TabPage page ) : int
page TabPage
return int
Beispiel #1
0
            public override void Remove(Control value)
            {
                bool change_index = false;

                TabPage page = value as TabPage;

                if (page != null && owner.Controls.Contains(page))
                {
                    int index = owner.IndexForTabPage(page);
                    if (index < owner.SelectedIndex || owner.SelectedIndex == Count - 1)
                    {
                        change_index = true;
                    }
                }
                base.Remove(value);
                owner.m_helper.Remove(page);
                // We don't want to raise SelectedIndexChanged until after we
                // have removed from the collection, so TabCount will be
                // correct for the user.
                if (change_index && Count > 0)
                {
                    // Clear the selected index internally, to avoid trying to access the previous
                    // selected tab when setting the new one - this is what .net seems to do
                    int prev_selected_index = owner.SelectedIndex;
                    owner.selected_index = -1;

                    owner.SelectedIndex = --prev_selected_index;
                    owner.Invalidate();
                }
                else if (change_index)
                {
                    owner.selected_index = -1;
                    owner.OnSelectedIndexChanged(EventArgs.Empty);
                    owner.Invalidate();
                }
                else
                {
                    owner.Redraw();
                }
            }
Beispiel #2
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;
                }
            }

            interior = new Rectangle(bounds.Left + focusRectSpacing.X + borderThickness.Left,
                                     bounds.Top + focusRectSpacing.Y +  +borderThickness.Top,
                                     bounds.Width - (focusRectSpacing.X * 2) - borderThickness.Width + 1,
                                     bounds.Height - (focusRectSpacing.Y * 2) - borderThickness.Height);

            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, page.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, page.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 (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count)
                    {
                        int image_y = interior.Y + (interior.Height - tab.ImageList.ImageSize.Height) / 2;
                        tab.ImageList.Draw(dc, new Point(interior.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, page.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);
            }

            if (page.Parent.Focused && is_selected && tab.ShowFocusCues)
            {
                interior.Width -= 1;
                ThemeEngine.Current.CPDrawFocusRectangle(dc, interior, tab.ForeColor, tab.BackColor);
            }

            return(res);
        }
Beispiel #3
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);
        }
Beispiel #4
0
		protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
		{
			int FlatButtonSpacing = 8;
			Rectangle interior;
			int res = bounds.Width;
			
			if (page.BackColor != tab_selected_gradient_second_color)
				page.BackColor = tab_selected_gradient_second_color;
			
			// we can't fill the background right away because the bounds might be adjusted if the tab is selected
			
			StringFormat string_format = new StringFormat ();
			
			if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
				dc.FillRectangle (ResPool.GetSolidBrush (tab_selected_gradient_second_color), bounds);
				
				// Separators
				if (tab.Appearance == TabAppearance.FlatButtons) {
					int width = bounds.Width;
					bounds.Width += (FlatButtonSpacing - 2);
					res = bounds.Width;
					CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
					bounds.Width = width;
				}
				
				if (is_selected) {
					CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
				} else if (tab.Appearance != TabAppearance.FlatButtons) {
					CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
				}
				
				interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
				
				string_format.Alignment = StringAlignment.Center;
				string_format.LineAlignment = StringAlignment.Center;
				string_format.FormatFlags = StringFormatFlags.NoWrap;
			} else {
				Color tab_first_color = is_selected ? tab_selected_gradient_first_color : tab_not_selected_gradient_first_color;
				Color tab_second_color = is_selected ? tab_selected_gradient_second_color : tab_not_selected_gradient_second_color;
				
				switch (tab.Alignment) {
				case TabAlignment.Top:
					
					Rectangle tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom), tab_first_color, tab_second_color)) {
						dc.FillRectangle (lgbr, tab_interior);
					}
					
					// edges
					Pen tmp_pen = ResPool.GetPen (tab_edge_color);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 1, bounds.Left + 1, bounds.Top);
					dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top, bounds.Right, bounds.Top + 1);
					
					// inner border
					tmp_pen = ResPool.GetPen (Color.White);
					dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 1);
					dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 1);
					
					// border
					tmp_pen = ResPool.GetPen (border_pressed_dark_color);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
					dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
					dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_dark_color, border_pressed_light_color)) {
						int diff = is_selected ? 3 : 2;
						using (Pen lgbrpen = new Pen (lgbr)) {
							dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - diff);
							dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Right, bounds.Bottom - diff);
						}
					}
					
					if (page.Focused) {
						tmp_pen = ResPool.GetPen (tab_focus_color);
						dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top  + 2, bounds.Right - 1, bounds.Top + 2);
						dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
						
						tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
						dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
						dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
						dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
					}
					
					interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
					
					string_format.Alignment = StringAlignment.Center;
					string_format.LineAlignment = StringAlignment.Center;
					string_format.FormatFlags = StringFormatFlags.NoWrap;
					
					break;
					
				case TabAlignment.Bottom:
					
					tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom - 1), tab_first_color, tab_second_color)) {
						dc.FillRectangle (lgbr, tab_interior);
					}
					
					// edges
					tmp_pen = ResPool.GetPen (tab_edge_color);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
					dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom, bounds.Right, bounds.Bottom - 1);
					
					// inner border
					tmp_pen = ResPool.GetPen (Color.White);
					dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 2);
					dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
					
					// border
					tmp_pen = ResPool.GetPen (border_pressed_dark_color);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
					dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
					dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_light_color, border_pressed_dark_color)) {
						int diff = is_selected ? 3 : 2;
						using (Pen lgbrpen = new Pen (lgbr)) {
							dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
							dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
						}
					}
					
					if (page.Focused) {
						tmp_pen = ResPool.GetPen (tab_focus_color);
						dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Bottom - 2);
						dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
						
						tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
						dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
						dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
						dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
					}
					
					interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
					
					string_format.Alignment = StringAlignment.Center;
					string_format.LineAlignment = StringAlignment.Center;
					string_format.FormatFlags = StringFormatFlags.NoWrap;
					
					break;
					
				case TabAlignment.Left:
					
					int w_diff = is_selected ? 2 : 0;
					
					tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2 - w_diff, bounds.Height - 2);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Right - w_diff, bounds.Top + 2), tab_first_color, tab_second_color)) {
						dc.FillRectangle (lgbr, tab_interior);
					}
					
					// edges
					tmp_pen = ResPool.GetPen (tab_edge_color);
					dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top, bounds.Left, bounds.Top + 1);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
					
					// inner border
					tmp_pen = ResPool.GetPen (Color.White);
					dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 3, bounds.Top + 1);
					dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
					
					// border
					tmp_pen = ResPool.GetPen (border_pressed_dark_color);
					dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Left, bounds.Top + 2);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);
					dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_dark_color, border_pressed_light_color)) {
						int diff = is_selected ? 3 : 1;
						
						using (Pen lgbrpen = new Pen (lgbr)) {
							dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Top, bounds.Right - diff, bounds.Left + 2);
							dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Bottom, bounds.Right - diff, bounds.Left + 2);
						}
					}
					
					if (page.Focused) {
						tmp_pen = ResPool.GetPen (tab_focus_color);
						dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top + 1, bounds.Left + 3, bounds.Bottom - 1);
						dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 2, bounds.Left + 2, bounds.Bottom - 2);
						
						tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
						dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top, bounds.Left + 1, bounds.Top + 2);
						dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
						dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);
					}
					
					interior = new Rectangle (bounds.Left + 2, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
					
					string_format.Alignment = StringAlignment.Center;
					string_format.LineAlignment = StringAlignment.Center;
					string_format.FormatFlags = StringFormatFlags.NoWrap;
					string_format.FormatFlags = StringFormatFlags.DirectionVertical;
					
					break;
					
				default:
					// TabAlignment.Right
					
					tab_interior = new Rectangle (bounds.Left, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right, bounds.Top + 2), tab_second_color, tab_first_color)) {
						dc.FillRectangle (lgbr, tab_interior);
					}
					
					int l_diff = is_selected ? 2 : 0;
					
					// edges
					tmp_pen = ResPool.GetPen (tab_edge_color);
					dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right - 1, bounds.Top + 1);
					dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom);
					
					// inner border
					tmp_pen = ResPool.GetPen (Color.White);
					dc.DrawLine (tmp_pen, bounds.Left + l_diff, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
					dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
					
					// border
					tmp_pen = ResPool.GetPen (border_pressed_dark_color);
					dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
					dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
					dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
					
					using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_light_color, border_pressed_dark_color)) {
						int diff = is_selected ? 3 : 1;
						
						using (Pen lgbrpen = new Pen (lgbr)) {
							dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Top, bounds.Right - diff, bounds.Top);
							dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Bottom, bounds.Right - diff, bounds.Bottom);
						}
					}
					
					if (page.Focused) {
						tmp_pen = ResPool.GetPen (tab_focus_color);
						dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top + 1, bounds.Right - 3, bounds.Bottom - 1);
						dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
						
						tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
						dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
						dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
						dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
					}
					
					interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
					
					string_format.Alignment = StringAlignment.Center;
					string_format.LineAlignment = StringAlignment.Center;
					string_format.FormatFlags = StringFormatFlags.NoWrap;
					string_format.FormatFlags = StringFormatFlags.DirectionVertical;
					
					break;
				}
			}
			
			if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
				if (tab.Alignment == TabAlignment.Left) {
					int wo = interior.Width / 2;
					int ho = interior.Height / 2;
					dc.TranslateTransform (interior.X + wo, interior.Y + ho);
					dc.RotateTransform (180);
					dc.DrawString (page.Text, page.Font, ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
					dc.ResetTransform ();
				} else {
					dc.DrawString (page.Text, page.Font,
						       ResPool.GetSolidBrush (SystemColors.ControlText),
						       interior, string_format);
				}
			} 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;
			}
			
			return res;
		}