private Rectangle GetTabTextRect(int index)
{
Rectangle textRect = new Rectangle();
using (GraphicsPath path = this._StyleProvider.GetTabBorder(index)){
RectangleF tabBounds = path.GetBounds();
textRect = new Rectangle((int)tabBounds.X, (int)tabBounds.Y, (int)tabBounds.Width, (int)tabBounds.Height);
// Make it shorter or thinner to fit the height or width because of the padding added to the tab for painting
switch (this.Alignment) {
case TabAlignment.Top:
textRect.Y += 4;
textRect.Height -= 6;
break;
case TabAlignment.Bottom:
textRect.Y += 2;
textRect.Height -= 6;
break;
case TabAlignment.Left:
textRect.X += 4;
textRect.Width -= 6;
break;
case TabAlignment.Right:
textRect.X += 2;
textRect.Width -= 6;
break;
}
// If there is an image allow for it
if (this.ImageList != null && (this.TabPages[index].ImageIndex > -1
|| (!string.IsNullOrEmpty(this.TabPages[index].ImageKey)
&& !this.TabPages[index].ImageKey.Equals("(none)", StringComparison.OrdinalIgnoreCase)))){
Rectangle imageRect = this.GetTabImageRect(index);
if ((this._StyleProvider.ImageAlign & NativeMethods.AnyLeftAlign) != ((ContentAlignment) 0)) {
if (this.Alignment <= TabAlignment.Bottom) {
textRect.X = imageRect.Right + 4;
textRect.Width -= (textRect.Right - (int)tabBounds.Right);
} else {
textRect.Y = imageRect.Y + 4;
textRect.Height -= (textRect.Bottom - (int)tabBounds.Bottom);
}
// If there is a closer allow for it
if (this._StyleProvider.ShowTabCloser) {
Rectangle closerRect = this.GetTabCloserRect(index);
if (this.Alignment <= TabAlignment.Bottom) {
if (this.RightToLeftLayout){
textRect.Width -= (closerRect.Right + 4 - textRect.X);
textRect.X = closerRect.Right + 4;
} else {
textRect.Width -= ((int)tabBounds.Right - closerRect.X + 4);
}
} else {
if (this.RightToLeftLayout){
textRect.Height -= (closerRect.Bottom + 4 - textRect.Y);
textRect.Y = closerRect.Bottom + 4;
} else {
textRect.Height -= ((int)tabBounds.Bottom - closerRect.Y + 4);
}
}
}
} else if ((this._StyleProvider.ImageAlign & NativeMethods.AnyCenterAlign) != ((ContentAlignment) 0)) {
// If there is a closer allow for it
if (this._StyleProvider.ShowTabCloser) {
Rectangle closerRect = this.GetTabCloserRect(index);
if (this.Alignment <= TabAlignment.Bottom) {
if (this.RightToLeftLayout){
textRect.Width -= (closerRect.Right + 4 - textRect.X);
textRect.X = closerRect.Right + 4;
} else {
textRect.Width -= ((int)tabBounds.Right - closerRect.X + 4);
}
} else {
if (this.RightToLeftLayout){
textRect.Height -= (closerRect.Bottom + 4 - textRect.Y);
textRect.Y = closerRect.Bottom + 4;
} else {
textRect.Height -= ((int)tabBounds.Bottom - closerRect.Y + 4);
}
}
}
} else {
if (this.Alignment <= TabAlignment.Bottom) {
textRect.Width -= ((int)tabBounds.Right - imageRect.X + 4);
} else {
textRect.Height -= ((int)tabBounds.Bottom - imageRect.Y + 4);
}
// If there is a closer allow for it
if (this._StyleProvider.ShowTabCloser) {
Rectangle closerRect = this.GetTabCloserRect(index);
if (this.Alignment <= TabAlignment.Bottom) {
if (this.RightToLeftLayout){
textRect.Width -= (closerRect.Right + 4 - textRect.X);
textRect.X = closerRect.Right + 4;
} else {
textRect.Width -= ((int)tabBounds.Right - closerRect.X + 4);
}
} else {
if (this.RightToLeftLayout){
textRect.Height -= (closerRect.Bottom + 4 - textRect.Y);
textRect.Y = closerRect.Bottom + 4;
} else {
textRect.Height -= ((int)tabBounds.Bottom - closerRect.Y + 4);
}
}
}
}
} else {
// If there is a closer allow for it
if (this._StyleProvider.ShowTabCloser) {
Rectangle closerRect = this.GetTabCloserRect(index);
if (this.Alignment <= TabAlignment.Bottom) {
if (this.RightToLeftLayout){
textRect.Width -= (closerRect.Right + 4 - textRect.X);
textRect.X = closerRect.Right + 4;
} else {
textRect.Width -= ((int)tabBounds.Right - closerRect.X + 4);
}
} else {
if (this.RightToLeftLayout){
textRect.Height -= (closerRect.Bottom + 4 - textRect.Y);
textRect.Y = closerRect.Bottom + 4;
} else {
textRect.Height -= ((int)tabBounds.Bottom - closerRect.Y + 4);
}
}
}
}
// Ensure it fits inside the path at the centre line
if (this.Alignment <= TabAlignment.Bottom) {
while (!path.IsVisible(textRect.Right, textRect.Y) && textRect.Width > 0){
textRect.Width -= 1;
}
while (!path.IsVisible(textRect.X, textRect.Y) && textRect.Width > 0) {
textRect.X += 1;
textRect.Width -= 1;
}
} else {
while (!path.IsVisible(textRect.X, textRect.Bottom) && textRect.Height > 0) {
textRect.Height -= 1;
}
while (!path.IsVisible(textRect.X, textRect.Y) && textRect.Height > 0) {
textRect.Y += 1;
textRect.Height -= 1;
}
}
}
return textRect;
}