private void DrawTabButton(int index, Graphics g, ref Rectangle tabBounds, ref Rectangle textTabBounds, Color ButtonColour, Color SelectedButtonColour, int ButtonSelected, ShowButtonEnum Button) { Pen buttonPen; // Get the bounds of the quit button based on the size of the tab Rectangle buttonBounds = GetButtonRect(tabBounds, Button); // If the user has his mouse over the button then set the foreground pen to... if (index == ButtonSelected) { buttonPen = new Pen(SelectedButtonColour); //set it to red } else { buttonPen = new Pen(Color.Black); //otherwise set it to standard black } // If the user wants to draw the background and the box, do it if (DrawTabButtonBox) { g.FillRectangle(new SolidBrush(ButtonColour), buttonBounds); g.DrawRectangle(buttonPen, buttonBounds); } // Make the rectangle a little bit smaller for painting the crosshair buttonBounds = Rectangle.Inflate(buttonBounds, -2, -2); if (Button == ShowButtonEnum.Quit) { // Draw the crosshair g.DrawLine(buttonPen, new Point(buttonBounds.Left, buttonBounds.Top), new Point(buttonBounds.Right, buttonBounds.Bottom)); g.DrawLine(buttonPen, new Point(buttonBounds.Left, buttonBounds.Bottom), new Point(buttonBounds.Right, buttonBounds.Top)); } else { g.DrawLine(buttonPen, new Point(buttonBounds.Left, buttonBounds.Top), new Point(buttonBounds.X + buttonBounds.Width / 2, buttonBounds.Bottom)); g.DrawLine(buttonPen, new Point(buttonBounds.Right, buttonBounds.Top), new Point(buttonBounds.X + buttonBounds.Width / 2, buttonBounds.Bottom)); } // Set the text boundary rectangle to if (Alignment == TabAlignment.Right || Alignment == TabAlignment.Left) { textTabBounds = new Rectangle(new Point(textTabBounds.X, buttonBounds.Bottom + GetTabButtonVerticalMarginSeparation(ItemSize)), new Size(textTabBounds.Width, textTabBounds.Height - buttonBounds.Height)); } else { textTabBounds = new Rectangle(textTabBounds.Location, new Size(buttonBounds.X - textTabBounds.X, textTabBounds.Height)); } }
/// <summary> /// Returns the rectangle which will be used to draw the quit button /// </summary> /// <param name="CurrentTabRect"></param> /// <returns></returns> private Rectangle GetButtonRect(Rectangle CurrentTabRect, ShowButtonEnum Button) { int TabBoundsRightMargin = 0; Rectangle tabButtonRect; if (Alignment == TabAlignment.Bottom || Alignment == TabAlignment.Top) { TabBoundsRightMargin = CurrentTabRect.Right - GetTabButtonHorizontalMarginSeparation(ItemSize); } else { TabBoundsRightMargin = (CurrentTabRect.X + (CurrentTabRect.Width / 2)) - (GetTabButtonWidth(ItemSize) / 2); } tabButtonRect = new Rectangle(TabBoundsRightMargin, CurrentTabRect.Top + GetTabButtonVerticalMarginSeparation(ItemSize), GetTabButtonWidth(ItemSize), GetTabButtonHeight(ItemSize)); if (Button == ShowButtonEnum.Quit) { return tabButtonRect; } if ((ShowButtons & ShowButtonEnum.Quit) == ShowButtonEnum.Quit) { if (Alignment == TabAlignment.Bottom || Alignment == TabAlignment.Top) //if the quit button exists then we should move the options button out of the way { tabButtonRect.X -= GetTabButtonWidth(ItemSize) + GetTabButtonHorizontalSeparation(ItemSize); } else { tabButtonRect.Y += GetTabButtonHeight(ItemSize) + GetTabButtonHorizontalSeparation(ItemSize); } } return tabButtonRect; }