private Rectangle GetTabImageRect(GraphicsPath tabBorderPath)
{
Rectangle imageRect = new Rectangle();
RectangleF rect = tabBorderPath.GetBounds();
// 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:
rect.Y += 4;
rect.Height -= 6;
break;
case TabAlignment.Bottom:
rect.Y += 2;
rect.Height -= 6;
break;
case TabAlignment.Left:
rect.X += 4;
rect.Width -= 6;
break;
case TabAlignment.Right:
rect.X += 2;
rect.Width -= 6;
break;
}
// Ensure image is fully visible
if (this.Alignment <= TabAlignment.Bottom) {
if ((this._StyleProvider.ImageAlign & NativeMethods.AnyLeftAlign) != ((ContentAlignment) 0)){
imageRect = new Rectangle((int)rect.X, (int)rect.Y + (int)Math.Floor((double)((int)rect.Height - 16)/2), 16, 16);
while (!tabBorderPath.IsVisible(imageRect.X, imageRect.Y)) {
imageRect.X += 1;
}
imageRect.X += 4;
} else if ((this._StyleProvider.ImageAlign & NativeMethods.AnyCenterAlign) != ((ContentAlignment) 0)){
imageRect = new Rectangle((int)rect.X + (int)Math.Floor((double)(((int)rect.Right - (int)rect.X - (int)rect.Height + 2)/2)), (int)rect.Y + (int)Math.Floor((double)((int)rect.Height - 16)/2), 16, 16);
} else {
imageRect = new Rectangle((int)rect.Right, (int)rect.Y + (int)Math.Floor((double)((int)rect.Height - 16)/2), 16, 16);
while (!tabBorderPath.IsVisible(imageRect.Right, imageRect.Y)) {
imageRect.X -= 1;
}
imageRect.X -= 4;
// Move it in further to allow for the tab closer
if (this._StyleProvider.ShowTabCloser && !this.RightToLeftLayout){
imageRect.X -= 10;
}
}
} else {
if ((this._StyleProvider.ImageAlign & NativeMethods.AnyLeftAlign) != ((ContentAlignment) 0)){
imageRect = new Rectangle((int)rect.X + (int)Math.Floor((double)((int)rect.Width - 16)/2), (int)rect.Y, 16, 16);
while (!tabBorderPath.IsVisible(imageRect.X, imageRect.Y)) {
imageRect.Y += 1;
}
imageRect.Y += 4;
} else if ((this._StyleProvider.ImageAlign & NativeMethods.AnyCenterAlign) != ((ContentAlignment) 0)){
imageRect = new Rectangle((int)rect.X + (int)Math.Floor((double)((int)rect.Width - 16)/2), (int)rect.Y + (int)Math.Floor((double)(((int)rect.Bottom - (int)rect.Y - (int)rect.Width + 2)/2)), 16, 16);
} else {
imageRect = new Rectangle((int)rect.X + (int)Math.Floor((double)((int)rect.Width - 16)/2), (int)rect.Bottom , 16, 16);
while (!tabBorderPath.IsVisible(imageRect.X, imageRect.Bottom)) {
imageRect.Y -= 1;
}
imageRect.Y -= 4;
// Move it in further to allow for the tab closer
if (this._StyleProvider.ShowTabCloser && !this.RightToLeftLayout){
imageRect.Y -= 10;
}
}
}
return imageRect;
}