private void CustomPaint(Graphics screenGraphics)
{
// We render into a bitmap that is then drawn in one shot rather than using
// double buffering built into the control as the built in buffering
// messes up the background painting.
// Equally the .Net 2.0 BufferedGraphics object causes the background painting
// to mess up, which is why we use this .Net 1.1 buffering technique.
// Buffer code from Gil. Schmidt http://www.codeproject.com/KB/graphics/DoubleBuffering.aspx
if (this.Width > 0 && this.Height > 0){
if (this._BackImage == null){
// Cached Background Image
this._BackImage = new Bitmap(this.Width, this.Height);
Graphics backGraphics = Graphics.FromImage(this._BackImage);
backGraphics.Clear(Color.Transparent);
this.PaintTransparentBackground(backGraphics, this.ClientRectangle);
}
this._BackBufferGraphics.Clear(Color.Transparent);
this._BackBufferGraphics.DrawImageUnscaled(this._BackImage, 0, 0);
this._TabBufferGraphics.Clear(Color.Transparent);
if (this.TabCount > 0) {
// When top or bottom and scrollable we need to clip the sides from painting the tabs.
// Left and right are always multiline.
if (this.Alignment <= TabAlignment.Bottom && !this.Multiline){
this._TabBufferGraphics.Clip = new Region(new RectangleF(this.ClientRectangle.X + 3, this.ClientRectangle.Y, this.ClientRectangle.Width - 6, this.ClientRectangle.Height));
}
// Draw each tabpage from right to left. We do it this way to handle
// the overlap correctly.
if (this.Multiline) {
for (int row = 0; row < this.RowCount; row++) {
for (int index = this.TabCount - 1; index >= 0; index--) {
if (index != this.SelectedIndex && (this.RowCount == 1 || this.GetTabRow(index) == row)) {
this.DrawTabPage(index, this._TabBufferGraphics);
}
}
}
} else {
for (int index = this.TabCount - 1; index >= 0; index--) {
if (index != this.SelectedIndex) {
this.DrawTabPage(index, this._TabBufferGraphics);
}
}
}
// The selected tab must be drawn last so it appears on top.
if (this.SelectedIndex > -1) {
this.DrawTabPage(this.SelectedIndex, this._TabBufferGraphics);
}
}
this._TabBufferGraphics.Flush();
// Paint the tabs on top of the background
// Create a new color matrix and set the alpha value to 0.5
ColorMatrix alphaMatrix = new ColorMatrix();
alphaMatrix.Matrix00 = alphaMatrix.Matrix11 = alphaMatrix.Matrix22 = alphaMatrix.Matrix44 = 1;
alphaMatrix.Matrix33 = this._StyleProvider.Opacity;
// Create a new image attribute object and set the color matrix to
// the one just created
using (ImageAttributes alphaAttributes = new ImageAttributes()){
alphaAttributes.SetColorMatrix(alphaMatrix);
// Draw the original image with the image attributes specified
this._BackBufferGraphics.DrawImage(this._TabBuffer,
new Rectangle(0,0,this._TabBuffer.Width, this._TabBuffer.Height),
0,0,this._TabBuffer.Width, this._TabBuffer.Height, GraphicsUnit.Pixel,
alphaAttributes);
}
this._BackBufferGraphics.Flush();
// Now paint this to the screen
// We want to paint the whole tabstrip and border every time
// so that the hot areas update correctly, along with any overlaps
// paint the tabs etc.
if (this.RightToLeftLayout){
screenGraphics.DrawImageUnscaled(this._BackBuffer, -1, 0);
} else {
screenGraphics.DrawImageUnscaled(this._BackBuffer, 0, 0);
}
}
}