Example #1
0
        private void drawHeader()
        {
            RECT tr = new RECT();
            RECT wr = new RECT();
            cStoreDc tempDc = new cStoreDc();
            int offset = 0;

            // set up the temp dc
            GetWindowRect(_hHeaderWnd, ref wr);
            OffsetRect(ref wr, -wr.Left, -wr.Top);
            tempDc.Height = wr.Bottom;
            tempDc.Width = wr.Right;

            int width = _cHeaderDc.Width / 4;

            for (int i = 0; i < ColumnCount; i++) 
            {
                if (!Enabled())
                {
                    offset = width * 3;
                }
                else if (i == focusedColumn())
                {
                    if (leftKeyPressed())
                        offset = width * 2;
                    else
                        offset = width;
                }
                else
                {
                    offset = 0;
                }
                SendMessage(_hHeaderWnd, HDM_GETITEMRECT, i, ref tr);
                using (StretchImage st = new StretchImage(_cHeaderDc.Hdc, tempDc.Hdc, new Rectangle(offset, 0, width, _cHeaderDc.Height), new Rectangle(tr.Left, tr.Top, tr.Right - tr.Left, tr.Bottom - tr.Top), 3, StretchModeEnum.STRETCH_HALFTONE)) { }
                // button, icon, sort arrows and text
                if (hasButton(i))
                    drawButton(tempDc.Hdc, i, tr);
                if (hasSort(i))
                    drawSortArrow(tempDc.Hdc, i, tr);
                if (hasIcon(i))
                    drawIcon(tempDc.Hdc, i, tr);
                drawText(tempDc.Hdc, i, tr);
            }
            // draw the end piece
            SendMessage(_hHeaderWnd, HDM_GETITEMRECT, columnAtIndex(ColumnCount - 1), ref tr);
            int left = tr.Right;
            GetWindowRect(_hHeaderWnd, ref tr);
            OffsetRect(ref tr, -tr.Left, -tr.Top);
            tr.Left = left;
            tr.Right += 10;
            using (StretchImage st = new StretchImage(_cHeaderDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, (_cHeaderDc.Width / 3) - 2, _cHeaderDc.Height), new Rectangle(tr.Left, tr.Top, tr.Right - tr.Left + 2, tr.Bottom - tr.Top), 3, StretchModeEnum.STRETCH_HALFTONE)) { }
            // blit the temp dc
            IntPtr hdc = GetDC(_hHeaderWnd);
            BitBlt(hdc, 0, 0, wr.Right, wr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            ReleaseDC(_hHeaderWnd, hdc);
            tempDc.Dispose();
        }
        private void drawScrollBar()
        {
            SCROLLBARINFO sbi = new SCROLLBARINFO();
            RECT tr = new RECT();
            cStoreDc tempDc = new cStoreDc();
            int offset = 0;
            int width = 0;
            int section = 0;

            GetWindowRect(_hScrollBarWnd, ref tr);
            OffsetRect(ref tr, -tr.Left, -tr.Top);
            tempDc.Width = tr.Right;
            tempDc.Height = tr.Bottom;
            SB_HITEST hitTest = scrollbarHitTest();

            sbi.cbSize = Marshal.SizeOf(sbi);
            SendMessage(_hScrollBarWnd, SBM_GETSCROLLBARINFO, 0, ref sbi);

            if (Direction == Orientation.Horizontal)
            {
                // draw the track
                using (StretchImage si = new StretchImage(_cTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTrackDc.Width, _cTrackDc.Height), new Rectangle(_iArrowCx, 0, tr.Right - (2 * _iArrowCx), tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                // draw the arrows
                section = 7;
                width = _cArrowDc.Width / section;
                // left arrow
                if (hitTest == SB_HITEST.leftArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // right arrow
                if (hitTest == SB_HITEST.rightArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;
                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(tr.Right - _iArrowCx, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                Point pst = getScrollBarThumb();
                using (StretchImage si = new StretchImage(_cThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cThumbDc.Height), new Rectangle(pst.X, 0, pst.Y - pst.X, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
            }
            else
            {
                // draw the track
                using (StretchImage si = new StretchImage(_cTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTrackDc.Width, _cTrackDc.Height), new Rectangle(0, _iArrowCy, tr.Right, tr.Bottom - (2 * _iArrowCy)), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                section = 6;
                width = _cArrowDc.Width / section;

                // top arrow
                if (hitTest == SB_HITEST.topArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, 0, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // bottom arrow
                if (hitTest == SB_HITEST.bottomArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;
                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cArrowDc.Height), new Rectangle(0, tr.Bottom - _iArrowCy, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;
                }
                else
                {
                    offset = 0;
                }
                Point pst = getScrollBarThumb();
                using (StretchImage si = new StretchImage(_cThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cThumbDc.Height), new Rectangle(0, pst.X, _iArrowCx, pst.Y - pst.X), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
            }
            IntPtr hdc = GetDC(_hMaskWnd);
            BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            ReleaseDC(_hMaskWnd, hdc);
            tempDc.Dispose();
        }
        private void drawTrackBar()
        {
            TrackBar tb = (TrackBar)Control.FromHandle(_hTrackBarWnd);
            int state = 0;
            int width = 0;
            int pos = 0;
            RECT trackRect = new RECT();
            RECT thumbRect = new RECT();
            RECT ctlRect = new RECT();
            cStoreDc tempDc = new cStoreDc();

            GetWindowRect(_hTrackBarWnd, ref ctlRect);
            OffsetRect(ref ctlRect, -ctlRect.Left, -ctlRect.Top);
            tempDc.Width = ctlRect.Right;
            tempDc.Height = ctlRect.Bottom;

            Graphics g = Graphics.FromHdc(tempDc.Hdc);

            SendMessage(_hTrackBarWnd, TBM_GETCHANNELRECT, 0, ref trackRect);
            SendMessage(_hTrackBarWnd, TBM_GETTHUMBRECT, 0, ref thumbRect);

            // get selected state
            if (!tb.Enabled)
            {
                state = 1;
            }
            else if (Hovering(thumbRect))
            {
                if (leftKeyPressed())
                    state = 2;
                else
                    state = 3;
            }
            else if (tb.Focused)
            {
                state = 2;
            }
            else
            {
                state = 0;
            }
            // draw the background
            using (Brush fillBrush = new SolidBrush(tb.BackColor))
                g.FillRectangle(fillBrush, tb.ClientRectangle);
            int ticks = SendMessage(_hTrackBarWnd, TBM_GETNUMTICS, 0, 0) - 1;


            if (tb.Orientation == Orientation.Horizontal)
            {
                if (tb.TickStyle == TickStyle.BottomRight)
                    pos = trackRect.Bottom + 13;
                else
                    pos = trackRect.Top - 15;

                // draw the ticks
                if (ticks > 0)
                {
                    for (int i = 0; i < ticks; i++)
                    {
                        int tX = SendMessage(_hTrackBarWnd, TBM_GETTICPOS, i, 0);
                        if (tX > 0)
                        {
                            using (Pen lightPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight)))
                                g.DrawLine(lightPen, new Point(tX - 1, pos), new Point(tX - 1, pos + 2));
                            using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
                                g.DrawLine(darkPen, new Point(tX, pos), new Point(tX, pos + 2));
                        }
                    }
                    // first tick
                    using (Pen lightPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight)))
                        g.DrawLine(lightPen, new Point(trackRect.Left + 4, pos), new Point(trackRect.Left + 4, pos + 2));
                    using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
                        g.DrawLine(darkPen, new Point(trackRect.Left + 5, pos), new Point(trackRect.Left + 5, pos + 2));
                    // last tick
                    using (Pen lightPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight)))
                        g.DrawLine(lightPen, new Point(trackRect.Right - 6, pos), new Point(trackRect.Right - 6, pos + 2));
                    using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
                        g.DrawLine(darkPen, new Point(trackRect.Right - 5, pos), new Point(trackRect.Right - 5, pos + 2));
                }
                width = ThumbGraphic.Width / 4;
                // draw the track and slider
                g.DrawImage(TrackGraphic, new Rectangle(trackRect.Left, trackRect.Top, trackRect.Right - trackRect.Left, trackRect.Bottom - trackRect.Top), new Rectangle(0, 0, TrackGraphic.Width, TrackGraphic.Height), GraphicsUnit.Pixel);
                g.DrawImage(ThumbGraphic, new Rectangle(thumbRect.Left, thumbRect.Top, thumbRect.Right - thumbRect.Left, thumbRect.Bottom - thumbRect.Top), new Rectangle(state * width, 0, width, ThumbGraphic.Height), GraphicsUnit.Pixel);
            }
            else
            {
                if (tb.TickStyle == TickStyle.BottomRight)
                    pos = trackRect.Bottom + 13;
                else
                    pos = trackRect.Top - 15;

                // draw the ticks
                if (ticks > 0)
                {
                    for (int i = 0; i < ticks; i++)
                    {
                        int tX = SendMessage(_hTrackBarWnd, TBM_GETTICPOS, i, 0);
                        if (tX > 0)
                        {
                            using (Pen lightPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight)))
                                g.DrawLine(lightPen, new Point(pos + 2, tX - 1), new Point(pos, tX - 1));
                            using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
                                g.DrawLine(darkPen, new Point(pos, tX), new Point(pos + 2, tX));
                        }
                    }
                    // first tick
                    using (Pen lightPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight)))
                        g.DrawLine(lightPen, new Point(pos, trackRect.Left + 4), new Point(pos + 2, trackRect.Left + 4));
                    using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
                        g.DrawLine(darkPen, new Point(pos, trackRect.Left + 5), new Point(pos + 2, trackRect.Left + 5));
                    // last tick
                    using (Pen lightPen = new Pen(Color.FromKnownColor(KnownColor.ControlLight)))
                        g.DrawLine(lightPen, new Point(pos, trackRect.Right - 6), new Point(pos + 2, trackRect.Right - 6));
                    using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
                        g.DrawLine(darkPen, new Point(pos, trackRect.Right - 5), new Point(pos + 2, trackRect.Right - 5));
                }
                Bitmap trc = (Bitmap)_oTrackBitmap.Clone();
                trc.RotateFlip(RotateFlipType.Rotate90FlipNone);
                Bitmap ttb = (Bitmap)_oThumbBitmap.Clone();
                ttb.RotateFlip(RotateFlipType.Rotate90FlipNone);
                width = ttb.Height / 4;
                g.DrawImage(trc, new Rectangle(trackRect.Top, trackRect.Left, trackRect.Bottom - trackRect.Top, trackRect.Right - trackRect.Left), new Rectangle(0, 0, trc.Width, trc.Height), GraphicsUnit.Pixel);
                g.DrawImage(ttb, new Rectangle(thumbRect.Left, thumbRect.Top, thumbRect.Right - thumbRect.Left, thumbRect.Bottom - thumbRect.Top), new Rectangle(0, width * state, ttb.Width, width), GraphicsUnit.Pixel);
            }
            g.Dispose();
            g = Graphics.FromHwnd(_hTrackBarWnd);
            BitBlt(g.GetHdc(), 0, 0, ctlRect.Right, ctlRect.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            g.ReleaseHdc();
            tempDc.Dispose();
            g.Dispose();
        }
        private void drawScrollBar()
        {
            RECT tr = new RECT();
            Point pst = new Point();
            cStoreDc tempDc = new cStoreDc();
            IntPtr hdc = IntPtr.Zero;
            int offset = 0;
            int width = 0;
            int section = 0;
            SCROLLBARINFO sb = new SCROLLBARINFO();
            sb.cbSize = Marshal.SizeOf(sb);

            if (hasHorizontal())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_HSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                tempDc.Width = tr.Right;
                tempDc.Height = tr.Bottom;
                SB_HITEST hitTest = scrollbarHitTest(Orientation.Horizontal);

                // draw the track
                using (StretchImage si = new StretchImage(_cHorizontalTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cHorizontalTrackDc.Width, _cHorizontalTrackDc.Height), new Rectangle(_iArrowCx, 0, tr.Right - (2 * _iArrowCx), tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                // draw the arrows
                section = 7;
                width = _cHorizontalArrowDc.Width / section;
                // left arrow
                if (hitTest == SB_HITEST.leftArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(0, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // right arrow
                if (hitTest == SB_HITEST.rightArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;

                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(tr.Right - _iArrowCx, 0, _iArrowCx, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cHorizontalThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }
                pst.X = sb.xyThumbTop;
                pst.Y = sb.xyThumbBottom;
                using (StretchImage si = new StretchImage(_cHorizontalThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalThumbDc.Height), new Rectangle(pst.X, 2, pst.Y - pst.X, tr.Bottom), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                hdc = GetDC(_hHorizontalMaskWnd);
                BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
                ReleaseDC(_hHorizontalMaskWnd, hdc);
            }

            if (hasSizer())
            {
                tempDc.Width = _iArrowCx;
                tempDc.Height = _iArrowCy;
                offset = 6;
                section = 7;
                width = _cHorizontalArrowDc.Width / section;

                using (StretchImage si = new StretchImage(_cHorizontalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cHorizontalArrowDc.Height), new Rectangle(0, 0, _iArrowCx, _iArrowCy), 0, StretchModeEnum.STRETCH_HALFTONE)) { }
                hdc = GetDC(_hSizerMaskWnd);
                BitBlt(hdc, 0, 0, _iArrowCx, _iArrowCy, tempDc.Hdc, 0, 0, 0xCC0020);
                ReleaseDC(_hSizerMaskWnd, hdc);
            }

            if (hasVertical())
            {
                GetScrollBarInfo(_hControlWnd, OBJID_VSCROLL, ref sb);
                tr = sb.rcScrollBar;
                OffsetRect(ref tr, -tr.Left, -tr.Top);
                tempDc.Width = tr.Right;
                tempDc.Height = tr.Bottom;
                SB_HITEST hitTest = scrollbarHitTest(Orientation.Vertical);

                // draw the track
                using (StretchImage si = new StretchImage(_cVerticalTrackDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cVerticalTrackDc.Width, _cVerticalTrackDc.Height), new Rectangle(0, _iArrowCy, tr.Right, tr.Bottom - (2 * _iArrowCy)), 2, StretchModeEnum.STRETCH_HALFTONE)) { }
                section = 6;
                width = _cVerticalArrowDc.Width / section;

                // top arrow
                if (hitTest == SB_HITEST.topArrow)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }
                using (StretchImage si = new StretchImage(_cVerticalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalArrowDc.Height), new Rectangle(0, 0, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // bottom arrow
                if (hitTest == SB_HITEST.bottomArrow)
                {
                    if (leftKeyPressed())
                        offset = 5;
                    else
                        offset = 4;

                }
                else
                {
                    offset = 3;
                }
                using (StretchImage si = new StretchImage(_cVerticalArrowDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalArrowDc.Height), new Rectangle(0, tr.Bottom - _iArrowCy, tr.Right, _iArrowCy), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                // draw the thumb
                section = 3;
                width = _cVerticalThumbDc.Width / section;
                if (hitTest == SB_HITEST.button)
                {
                    if (leftKeyPressed())
                        offset = 2;
                    else
                        offset = 1;

                }
                else
                {
                    offset = 0;
                }

                pst.X = sb.xyThumbTop;
                pst.Y = sb.xyThumbBottom;
                using (StretchImage si = new StretchImage(_cVerticalThumbDc.Hdc, tempDc.Hdc, new Rectangle(offset * width, 0, width, _cVerticalThumbDc.Height), new Rectangle(0, pst.X, _iArrowCx, pst.Y - pst.X), 2, StretchModeEnum.STRETCH_HALFTONE)) { }

                hdc = GetDC(_hVerticalMaskWnd);
                BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
                ReleaseDC(_hVerticalMaskWnd, hdc);
            }
            tempDc.Dispose();
        }
 private void renderTip()
 {
     if ((Caption != String.Empty) && (TipBounds != Rectangle.Empty))
     {
         // create the canvas
         _tClientBounds.Height = 50;
         Rectangle bounds = calculateSize();
         bounds.X = TipBounds.X;
         bounds.Y = TipBounds.Y;
         TipBounds = bounds;
         cStoreDc drawDc = new cStoreDc();
         drawDc.Width = TipBounds.Width;
         drawDc.Height = TipBounds.Height;
         positionWindow();
         // show the window
         showWindow(true);
         // draw the background to the temp dc
         drawBackground(drawDc.Hdc);
         // draw image and text
         if ((ItemImage != null) && (UseIcon))
             drawIcon(drawDc.Hdc);
         if (Title != String.Empty)
             drawTitle(drawDc.Hdc);
         drawCaption(drawDc.Hdc);
         // draw the tempdc to the window
         IntPtr hdc = GetDC(_hTipWnd);
         BitBlt(hdc, 0, 0, TipBounds.Width, TipBounds.Height, drawDc.Hdc, 0, 0, 0xCC0020);
         ReleaseDC(_hTipWnd, hdc);
         // cleanup
         drawDc.Dispose();
     }
 }
Example #6
0
        private void DrawWindow()
        {
            int imageWidth = 0;
            int imageHeight = 0;
            int drawWidth = 0;
            int drawHeight = 0;

            RECT windowRect = new RECT();
            GetWindowRect(ParentWnd, ref windowRect);
            OffsetRect(ref windowRect, -windowRect.Left, -windowRect.Top);
            int offset = Focused ? 0 : 1;
            if (Focused)
            {

            }
            cStoreDc windowDc = new cStoreDc();
            windowDc.Height = windowRect.Bottom;
            windowDc.Width = windowRect.Right;

            using (StretchMode mode = new StretchMode(windowDc.Hdc, StretchModeEnum.STRETCH_HALFTONE))
            {
                if ((ExcludeLeftEnd == 0) && (ExcludeRightEnd == 0))
                {
                    // top
                    imageWidth = _cCaptionBarDc.Width;
                    imageHeight = (_cCaptionBarDc.Height / 2);
                    drawWidth = windowRect.Right - ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2));
                    drawHeight = (_cCaptionBarDc.Height / 2);
                    StretchBlt(windowDc.Hdc, (_cLeftFrameDc.Width / 2), 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, 0, (imageHeight * offset), imageWidth, imageHeight, 0xCC0020);
                }
                else
                {
                    int pieceOffset = 0;
                    int centerLength = windowDc.Width - ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2));
                    // left exclusion area
                    if (ExcludeLeftEnd > 0)
                    {
                        // draw the start
                        if (ExcludeLeftStart > 0)
                        {
                            drawWidth = ExcludeLeftStart;
                            drawHeight = (_cCaptionBarDc.Height / 2);
                            pieceOffset = (_cLeftFrameDc.Width / 2);
                            StretchBlt(windowDc.Hdc, pieceOffset, 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, 0, (imageHeight * offset), drawWidth, drawHeight, 0xCC0020);
                        }
                        imageWidth = ExcludeLeftEnd - ExcludeLeftStart;
                        imageHeight = (_cCaptionBarDc.Height / 2);
                        pieceOffset = (_cLeftFrameDc.Width / 2) + ExcludeLeftStart;
                        BitBlt(windowDc.Hdc, pieceOffset, 0, imageWidth, imageHeight, _cCaptionBarDc.Hdc, ExcludeLeftStart, (imageHeight * offset), 0xCC0020);
                        centerLength -= ExcludeLeftEnd;
                    }
                    // right exclusion area
                    if (ExcludeRightEnd > 0)
                    {
                        imageWidth = ExcludeRightEnd - ExcludeRightStart;
                        imageHeight = (_cCaptionBarDc.Height / 2);
                        pieceOffset = windowDc.Width - ((_cRightFrameDc.Width / 2) + (_cCaptionBarDc.Width - ExcludeRightStart));
                        //if (pieceOffset > 0)
                        BitBlt(windowDc.Hdc, pieceOffset, 0, imageWidth, imageHeight, _cCaptionBarDc.Hdc, ExcludeRightStart, (imageHeight * offset), 0xCC0020);
                        centerLength -= imageWidth;
                    }
                    // draw the end
                    if (ExcludeRightEnd < _cCaptionBarDc.Width)
                    {
                        drawWidth = _cCaptionBarDc.Width - ExcludeRightEnd;
                        drawHeight = (_cCaptionBarDc.Height / 2);
                        pieceOffset += (ExcludeRightEnd - ExcludeRightStart);
                        StretchBlt(windowDc.Hdc, pieceOffset, 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, 0, (imageHeight * offset), drawWidth, drawHeight, 0xCC0020);
                        centerLength -= drawWidth;
                    }
                    // draw the center
                    if (ExcludeRightStart > 0)
                        imageWidth = _cCaptionBarDc.Width - (ExcludeRightStart - ExcludeLeftEnd);
                    else
                        imageWidth = _cCaptionBarDc.Width - ExcludeLeftEnd;

                    imageHeight = (_cCaptionBarDc.Height / 2);
                    pieceOffset = (_cLeftFrameDc.Width / 2) + ExcludeLeftEnd;
                    drawWidth = centerLength;
                    drawHeight = (_cCaptionBarDc.Height / 2);
                    StretchBlt(windowDc.Hdc, pieceOffset, 0, drawWidth, drawHeight, _cCaptionBarDc.Hdc, ExcludeLeftEnd, (imageHeight * offset), imageWidth, imageHeight, 0xCC0020);
                }

                // left
                imageWidth = (_cLeftFrameDc.Width / 2);
                imageHeight = _cLeftFrameDc.Height - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2));
                drawWidth = (_cLeftFrameDc.Width / 2);
                drawHeight = windowRect.Bottom - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2));
                StretchBlt(windowDc.Hdc, 0, (_cCaptionBarDc.Height / 2), drawWidth, drawHeight, _cLeftFrameDc.Hdc, (imageWidth * offset), (_cCaptionBarDc.Height / 2), imageWidth, imageHeight, 0xCC0020);
                //right
                imageWidth = (_cRightFrameDc.Width / 2);
                imageHeight = _cRightFrameDc.Height - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2));
                drawWidth = (_cRightFrameDc.Width / 2);
                drawHeight = windowRect.Bottom - ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2));
                StretchBlt(windowDc.Hdc, (windowRect.Right - imageWidth), (_cCaptionBarDc.Height / 2), drawWidth, drawHeight, _cRightFrameDc.Hdc, (imageWidth * offset), (_cCaptionBarDc.Height / 2), imageWidth, imageHeight, 0xCC0020);
                // bottom
                imageWidth = _cBottomFrameDc.Width;
                imageHeight = (_cBottomFrameDc.Height / 2);
                drawWidth = windowRect.Right - ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2));
                drawHeight = (_cBottomFrameDc.Height / 2);
                StretchBlt(windowDc.Hdc, (_cLeftFrameDc.Width / 2), windowRect.Bottom - (_cBottomFrameDc.Height / 2), drawWidth, drawHeight, _cBottomFrameDc.Hdc, 0, (imageHeight * offset), imageWidth, imageHeight, 0xCC0020);
            }
            // top left
            imageWidth = (_cLeftFrameDc.Width / 2);
            imageHeight = (_cCaptionBarDc.Height / 2);
            BitBlt(windowDc.Hdc, 0, 0, imageWidth, imageHeight, _cLeftFrameDc.Hdc, (imageWidth * offset), 0, 0xCC0020);
            // top right
            imageWidth = (_cRightFrameDc.Width / 2);
            imageHeight = (_cCaptionBarDc.Height / 2);
            BitBlt(windowDc.Hdc, (windowRect.Right - imageWidth), 0, imageWidth, imageHeight, _cRightFrameDc.Hdc, (imageWidth * offset), 0, 0xCC0020);
            // bottom left
            imageWidth = (_cLeftFrameDc.Width / 2);
            imageHeight = (_cBottomFrameDc.Height / 2);
            BitBlt(windowDc.Hdc, 0, (windowRect.Bottom - imageHeight), imageWidth, imageHeight, _cLeftFrameDc.Hdc, (imageHeight * offset), (_cLeftFrameDc.Height - imageHeight), 0xCC0020);
            // bottom right
            imageWidth = (_cRightFrameDc.Width / 2);
            imageHeight = (_cBottomFrameDc.Height / 2);
            BitBlt(windowDc.Hdc, (windowRect.Right - imageWidth), (windowRect.Bottom - imageHeight), imageWidth, imageHeight, _cRightFrameDc.Hdc, (imageHeight * offset), (_cRightFrameDc.Height - imageHeight), 0xCC0020);

            RECT captionRect = new RECT(0, 0, windowDc.Width, _cCaptionBarDc.Height / 2);

            DrawButtons(windowDc.Hdc, captionRect);
            DrawIcon(windowDc.Hdc, captionRect);
            DrawTitle(windowDc.Hdc, captionRect);

            // exclude client area
            imageWidth = (_cLeftFrameDc.Width / 2);
            imageHeight = (_cCaptionBarDc.Height / 2);
            //drawWidth = windowRect.Right - ((_leftFrameDc.Width / 2) + (_rightFrameDc.Width / 2));
            //drawHeight = windowRect.Bottom - ((_captionBarDc.Height / 2) + (_bottomFrameDc.Height / 2));
            drawWidth = ((_cLeftFrameDc.Width / 2) + (_cRightFrameDc.Width / 2));
            drawHeight = ((_cCaptionBarDc.Height / 2) + (_cBottomFrameDc.Height / 2));
            IntPtr hdc = GetWindowDC(ParentWnd);
            RECT clientRect = new RECT();
            GetWindowRect(ParentWnd, ref clientRect);
            OffsetRect(ref clientRect, -clientRect.Left, -clientRect.Top);
            OffsetRect(ref clientRect, -drawWidth, -drawHeight);

            ExcludeClipRect(hdc, imageWidth, imageHeight, clientRect.Right + imageWidth, clientRect.Bottom + imageHeight);
            // blit to window
            BitBlt(hdc, 0, 0, windowRect.Right, windowRect.Bottom, windowDc.Hdc, 0, 0, 0xCC0020);
            
            // clean up
            ReleaseDC(ParentWnd, hdc);
            windowDc.Dispose();
        }
        private void drawMask()
        {
            byte bt = 0;
            IntPtr hdc = IntPtr.Zero;
            cStoreDc tempDc = new cStoreDc();
            RECT tr = new RECT();

            GetWindowRect(_hControlWnd, ref tr);
            OffsetRect(ref tr, -tr.Left, -tr.Top);

            Rectangle bounds = new Rectangle(_areaRect.Left, _areaRect.Top, _areaRect.Right - _areaRect.Left, _areaRect.Bottom - _areaRect.Top);
            tempDc.Width = tr.Right;
            tempDc.Height = tr.Bottom;

            bt = (byte)(_maskTimer * 15);
            BitBlt(tempDc.Hdc, 0, 0, tr.Right, tr.Bottom, _cMaskDc.Hdc, 0, 0, 0xCC0020);
            using (AlphaStretch al = new AlphaStretch(_cTransitionDc.Hdc, tempDc.Hdc, new Rectangle(0, 0, _cTransitionDc.Width, _cTransitionDc.Height), bounds, 2, bt)) { }
            hdc = GetDC(_hControlWnd);
            BitBlt(hdc, 0, 0, tr.Right, tr.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            ReleaseDC(_hControlWnd, hdc);
            tempDc.Dispose();
            ValidateRect(_hControlWnd, ref tr);
        }
        private void drawProgressBar()
        {
            ProgressBar pb = (ProgressBar)Control.FromHandle(_hProgressBarWnd);
            RECT ctlRect = new RECT();
            cStoreDc tempDc = new cStoreDc();

            GetWindowRect(_hProgressBarWnd, ref ctlRect);
            OffsetRect(ref ctlRect, -ctlRect.Left, -ctlRect.Top);
            tempDc.Height = ctlRect.Bottom;
            tempDc.Width = ctlRect.Right;
            float length = (float)ctlRect.Right / ((float)pb.Maximum / (float)pb.Value);
            // draw the background
            alphaBlit(tempDc.Hdc, 0, 0, ctlRect.Right, ctlRect.Bottom, _cBufferDc.Hdc, 0, 0, _cBufferDc.Width, _cBufferDc.Height, 240);
            // draw the progress bar
            using (StretchMode mode = new StretchMode(tempDc.Hdc, StretchModeEnum.STRETCH_HALFTONE))
                StretchBlt(tempDc.Hdc, 1, 1, (int)length - 1, ctlRect.Bottom - 2, _cProgressBarDc.Hdc, 0, 0, _cProgressBarDc.Width, _cProgressBarDc.Height, 0xCC0020);

            Graphics g = Graphics.FromHwnd(_hProgressBarWnd);
            BitBlt(g.GetHdc(), 0, 0, ctlRect.Right, ctlRect.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            g.ReleaseHdc();
            g.Dispose();
            tempDc.Dispose();
        }
        private void drawTabControl()
        {
            // buffer drawing
            cStoreDc tempDc = new cStoreDc();
            int state = 0;
            RECT tabRect = new RECT();
            RECT ctlRect = new RECT();
            Rectangle headerRect = new Rectangle();
            TabControl tab = (TabControl)Control.FromHandle(_tabControlWnd);
            TabAlignment align = tab.Alignment;
            Rectangle fillRect = new Rectangle();

            // get size and dimension buffer dc
            GetWindowRect(_tabControlWnd, ref ctlRect);
            OffsetRect(ref ctlRect, -ctlRect.Left, -ctlRect.Top);
            tempDc.Width = ctlRect.Right;
            tempDc.Height = ctlRect.Bottom;
            Graphics g = Graphics.FromHdc(tempDc.Hdc);

            fillRect = new Rectangle(0, 0, ctlRect.Right, ctlRect.Bottom);
            // fill and backfill //
            if (tab.TabCount > 0)
            {
                // fill transparent section
                headerRect = new Rectangle(0, 0, ctlRect.Right, tab.DisplayRectangle.Y);
                using (Brush fillBrush = new SolidBrush(tab.Parent.BackColor))
                    g.FillRectangle(fillBrush, headerRect);
                // backfill the client
                headerRect = new Rectangle(0, tab.DisplayRectangle.Y, ctlRect.Right, ctlRect.Bottom - tab.DisplayRectangle.Y);
                using (Brush fillBrush = new SolidBrush(tab.Parent.BackColor))
                    g.FillRectangle(fillBrush, tab.ClientRectangle);
            }
            else
            {
                using (Brush fillBrush = new SolidBrush(Color.White))
                    g.FillRectangle(fillBrush, fillRect);
            }

            // draw the frame //
            //using (Pen darkPen = new Pen(Color.FromKnownColor(KnownColor.ControlDark)))
            using (Pen darkPen = new Pen(TabBorderColor)) //tester
            {
                Rectangle r = tab.DisplayRectangle;
                r.Inflate(1, 1);
                r.X--;
                r.Y--;
                g.DrawRectangle(darkPen, r);
            }

            // draw the tab headers //
            for (int i = 0; i < tab.TabCount; i++)
            {
                //tab.TabPages[i].Size = new Size(tab.TabPages[i].Size.Width + 5, tab.TabPages[i].Size.Height);
                // get the header size
                SendMessage(_tabControlWnd, TCM_GETITEMRECT, i, ref tabRect);

                // state
                if (tab.Enabled == false)
                    state = 3;
                else if (tab.SelectedTab == tab.TabPages[i])
                    state = 2;
                else if (Hovering(tabRect))
                    state = 1;
                else
                    state = 0;

                // bitmap mode //
                if (TabDrawingStyle == TabRenderStyle.Graphic && _tabHeaderBitmap != null)
                {
                    int width = _tabHeaderBitmap.Width / 4;
                    // create a new bitmap
                    Bitmap bm;
                    Bitmap cl;
                    int xsize = (state != 2) ? (tabRect.Bottom - tabRect.Top) : (tabRect.Bottom - tabRect.Top) - 7;
                    //xsize = (tabRect.Bottom - tabRect.Top) - 7;

                    // to maintain a constant border depth while stretching the bitmap //
                    if (align == TabAlignment.Bottom || align == TabAlignment.Top)
                        bm = new Bitmap(tabRect.Right - tabRect.Left, xsize);
                    else
                        bm = new Bitmap(xsize, tabRect.Right - tabRect.Left);

                    Graphics gcl = Graphics.FromImage(bm);
                    
                    // clone the inner portion
                    cl = _tabHeaderBitmap.Clone(new Rectangle((state * width) + 8, 0, width - 16, _tabHeaderBitmap.Height), System.Drawing.Imaging.PixelFormat.DontCare);
                    // draw to new bmp
                    if (align == TabAlignment.Bottom || align == TabAlignment.Top)
                        gcl.DrawImage(cl, new Rectangle(8, 0, tabRect.Right - tabRect.Left, xsize));
                    else
                        gcl.DrawImage(cl, new Rectangle(8, 0, xsize, tabRect.Right - tabRect.Left));

                    // clone and draw the edges
                    // left
                    cl = _tabHeaderBitmap.Clone(new Rectangle(state * width, 0, 8, _tabHeaderBitmap.Height), System.Drawing.Imaging.PixelFormat.DontCare);
                    gcl.DrawImage(cl, new Rectangle(0, 0, 8, xsize));
                    cl.Dispose();
                    // top
                    //cl = _tabHeaderBitmap.Clone(new Rectangle(state * width + 8, 0, width - 16, 7), System.Drawing.Imaging.PixelFormat.DontCare);
                    //gcl.DrawImage(cl, new Rectangle(8, 0, bm.Width - 16, 7));
                    //cl.Dispose();
                    //right
                    cl = _tabHeaderBitmap.Clone(new Rectangle((state * width) + (width - 16), 0, 16, _tabHeaderBitmap.Height), System.Drawing.Imaging.PixelFormat.Format64bppArgb);
                    gcl.DrawImage(cl, new Rectangle(bm.Width - 16, 0, 16, xsize));
                    cl.Dispose();
                    gcl.Dispose();
                    Rectangle dstRect = new Rectangle();

                    // set the base drawing coordinates //
                    switch (align)
                    {
                        case TabAlignment.Bottom:
                            dstRect = new Rectangle(tabRect.Left, tabRect.Top, tabRect.Right - tabRect.Left, tabRect.Bottom - tabRect.Top);
                            bm.RotateFlip(RotateFlipType.Rotate180FlipX);
                            if (state == 2)
                            {
                                dstRect.Height++;
                                dstRect.Y--;
                            }
                            break;
                        case TabAlignment.Left:
                            dstRect = new Rectangle(tabRect.Left, tabRect.Top, tabRect.Right - tabRect.Left, tabRect.Bottom - tabRect.Top);
                            bm.RotateFlip(RotateFlipType.Rotate90FlipX);
                            if (state == 2)
                                dstRect.Width++;
                            break;
                        case TabAlignment.Right:
                            dstRect = new Rectangle(tabRect.Left - 1, tabRect.Top, tabRect.Right - tabRect.Left, tabRect.Bottom - tabRect.Top);
                            bm.RotateFlip(RotateFlipType.Rotate90FlipNone);
                            if (state == 2)
                            {
                                dstRect.Width++;
                                dstRect.X--;
                            }
                            break;
                        case TabAlignment.Top:
                            dstRect = new Rectangle(tabRect.Left, tabRect.Top, tabRect.Right - tabRect.Left, tabRect.Bottom - tabRect.Top);
                            if (state == 2)
                                dstRect.Height++;
                            break;
                    }
                    // draw the image to temp dc
                    width = tabRect.Right - tabRect.Left;
                    Rectangle srcRect = new Rectangle(0, 0, bm.Width, bm.Height);
                    g.DrawImage(bm, dstRect, srcRect, GraphicsUnit.Pixel);
                    bm.Save(@"c:\full.bmp");
                    bm.Dispose();
                }
                // custom draw //
                else
                {
                    Color clBegin = TabGradientBegin;
                    Color clEnd = TabGradientEnd;
                    SendMessage(_tabControlWnd, TCM_GETITEMRECT, i, ref tabRect);
                    headerRect = new Rectangle(tabRect.Left, tabRect.Top, tabRect.Right - tabRect.Left, tabRect.Bottom - tabRect.Top);
                    // gradient color assignment
                    switch (align)
                    {
                        case TabAlignment.Bottom:
                            headerRect.Y -= 2;
                            clBegin = TabGradientBegin;
                            clEnd = (state == 2) ? TabSelectedColor : TabGradientEnd;
                            break;
                        case TabAlignment.Left:
                            clBegin = TabGradientBegin;
                            clEnd = (state == 2) ? TabSelectedColor : TabGradientEnd;
                            break;
                        case TabAlignment.Right:
                            headerRect.X -= 2;
                            clEnd = (state == 2) ? TabSelectedColor : TabGradientEnd;
                            clBegin = TabGradientBegin;
                            break;
                        case TabAlignment.Top:
                            clBegin = TabGradientBegin;
                            clEnd = (state == 2) ? TabSelectedColor : TabGradientEnd;
                            break;
                    }
                    if (tab.Enabled == false)
                    {
                        clBegin = Color.LightGray;
                        clEnd = Color.LightGray;
                    }
                    // draw the gradient
                    fillRect = headerRect;
                    fillRect.Inflate(-1, -1);
                    fillRect.Width++;
                    fillRect.Height++;
                    drawBlendedGradient(g,
                        (align == TabAlignment.Bottom || align == TabAlignment.Top) ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal,
                        clBegin,
                        (state == 1) ? TabFocusedColor : clEnd,
                        fillRect,
                        TabGradientBlend);
                    if (state == 1)
                    {
                        // selection mask
                        drawFocusedTab(g, headerRect, LinearGradientMode.Vertical);
                    }
                    else if (state == 2)
                    {
                        // draw selected tab header frame
                        using (Pen darkPen = new Pen(TabBorderColor))
                            g.DrawRectangle(darkPen, headerRect);
                        // cover edge
                        switch (align)
                        {
                            case TabAlignment.Bottom:
                                using (Pen edgePen = new Pen(clBegin))
                                    g.DrawLine(edgePen, new Point(headerRect.Left + 1, headerRect.Top), new Point(headerRect.Right - 1, headerRect.Top));
                                break;
                            case TabAlignment.Left:
                                using (Pen edgePen = new Pen(clBegin))
                                    g.DrawLine(edgePen, new Point(headerRect.Right, headerRect.Top + 1), new Point(headerRect.Right, headerRect.Bottom - 1));
                                break;
                            case TabAlignment.Right:
                                using (Pen edgePen = new Pen(clBegin))
                                    g.DrawLine(edgePen, new Point(headerRect.Left, headerRect.Top + 1), new Point(headerRect.Left, headerRect.Bottom - 1));
                                break;
                            case TabAlignment.Top:
                                using (Pen edgePen = new Pen(clBegin))
                                    g.DrawLine(edgePen, new Point(headerRect.Left + 1, headerRect.Bottom), new Point(headerRect.Right - 1, headerRect.Bottom));
                                break;
                        }
                    }
                    else
                    {
                        // frame inactive tabs
                        using (Pen darkPen = new Pen(Color.FromArgb(100, TabBorderColor)))
                            g.DrawRectangle(darkPen, headerRect);
                    }
                }

                // draw icon //
                int hoffset = 4;
                int voffset = 4;
                if (tab.ImageList != null)
                {
                    // calculate offsets and draw the icon
                    if (tab.TabPages[i].ImageIndex > -1)
                    {
                        if (align == TabAlignment.Top || align == TabAlignment.Bottom)
                        {
                            voffset = ((tabRect.Bottom - tabRect.Top) - tab.ImageList.Images[i].Size.Height) / 2;
                            hoffset = 4;
                            tab.ImageList.Draw(g, new Point(tabRect.Left + hoffset, tabRect.Top + voffset), tab.TabPages[i].ImageIndex);
                            hoffset += tab.ImageList.Images[i].Size.Width;
                        }
                        else if (align == TabAlignment.Right)
                        {
                            hoffset = ((tabRect.Right - tabRect.Left) - tab.ImageList.Images[i].Size.Width) / 2;
                            voffset = 4;
                            tab.ImageList.Draw(g, new Point(tabRect.Left + hoffset, tabRect.Top + voffset), tab.TabPages[i].ImageIndex);
                            voffset += tab.ImageList.Images[i].Size.Height;
                        }
                        else if (align == TabAlignment.Left)
                        {
                            hoffset = ((tabRect.Right - tabRect.Left) - tab.ImageList.Images[i].Size.Width) / 2;
                            voffset = (tab.ImageList.Images[i].Size.Height + 4);
                            tab.ImageList.Draw(g, new Point(tabRect.Left + hoffset, tabRect.Bottom - voffset), tab.TabPages[i].ImageIndex);
                            voffset = tab.ImageList.Images[i].Size.Height + 4;
                        }
                    }
                }

                // draw text //
                // text offsets
                SizeF sz = g.MeasureString(tab.TabPages[i].Text, tab.Font);
                if (align == TabAlignment.Top || align == TabAlignment.Bottom)
                    voffset = ((tabRect.Bottom - tabRect.Top) - (int)sz.Height) / 2;
                else
                    hoffset = ((tabRect.Right - tabRect.Left) - (int)sz.Height) / 2;

                // text graphics
                Graphics gx = Graphics.FromHdcInternal(tempDc.Hdc);
                using (StringFormat sf = new StringFormat())
                {
                    gx.SmoothingMode = SmoothingMode.AntiAlias;
                    gx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
                    sf.Alignment = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Near;
                    // poition and format
                    if (align == TabAlignment.Top || align == TabAlignment.Bottom)
                    {
                        hoffset += tabRect.Left;
                        voffset += tabRect.Top;
                    }
                    else if (align == TabAlignment.Left)
                    {
                        // create 'mirrored' text
                        // vertical text
                        sf.FormatFlags = StringFormatFlags.DirectionVertical;
                        // create a new matrix and rotate
                        Matrix mt = new Matrix();
                        mt.Rotate(180f);
                        // adjust offsets
                        voffset += -tabRect.Bottom;
                        hoffset += -tabRect.Right;
                        // apply the transform
                        gx.Transform = mt;

                    }
                    else if (align == TabAlignment.Right)
                    {
                        sf.FormatFlags = StringFormatFlags.DirectionVertical;
                        hoffset += tabRect.Left;
                        voffset += tabRect.Top;
                    }
                    // rtl
                    Font font = tab.Font;
                    if (tab.RightToLeftLayout)
                        sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
                    Color foreColor;
                    if (state == 1)
                        foreColor = TabFocusedForeColor;
                    else if (state == 2)
                        foreColor = System.Drawing.Color.FromArgb(21, 66, 139);
                    else
                    {
                        foreColor = Color.White;
                        font = new Font(tab.Font.FontFamily, tab.Font.Size, FontStyle.Regular);
                    }
                    // draw the text
                    using (Brush captionBrush = new SolidBrush(foreColor))
                        gx.DrawString(tab.TabPages[i].Text ,font , captionBrush, new RectangleF(hoffset, voffset, tabRect.Right - tabRect.Left, tabRect.Bottom - tabRect.Top), sf);
                }
                gx.Dispose();
            }

            g.Dispose();
            // draw the buffer to the control
            g = Graphics.FromHwnd(_tabControlWnd);
            BitBlt(g.GetHdc(), 0, 0, ctlRect.Right, ctlRect.Bottom, tempDc.Hdc, 0, 0, 0xCC0020);
            g.ReleaseHdc();
            tempDc.Dispose();
        }