示例#1
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (disposing)
     {
         if (backImageDc != null)
         {
             backImageDc.Dispose();
             backImageDc = null;
         }
     }
 }
示例#2
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (disposing)
            {
                if (_backDc != null)
                {
                    _backDc.Dispose();
                    _backDc = null;
                }

                if (!_titleFont.IsSystemFont)
                {
                    _titleFont.Dispose();
                }
                _titleFont = null;

                _image      = null;
                _colorTable = null;
            }
        }
示例#3
0
        private void DrawScrollBar(
            IntPtr maskHWnd,
            Rectangle bounds,
            Rectangle trackRect,
            Rectangle topLeftArrowRect,
            Rectangle bottomRightArrowRect,
            Rectangle thumbRect,
            ControlState topLeftArrowState,
            ControlState bottomRightArrowState,
            ControlState thumbState,
            Orientation direction)
        {
            bool            bHorizontal = direction == Orientation.Horizontal;
            ArrowDirection  arrowDirection;
            bool            bEnabled = _owner.Enabled;
            IScrollBarPaint paint    = _owner as IScrollBarPaint;

            if (paint == null)
            {
                return;
            }

            ImageDc tempDc = new ImageDc(bounds.Width, bounds.Height);
            IntPtr  hdc    = NativeMethods.GetDC(maskHWnd);

            try
            {
                using (Graphics g = Graphics.FromHdc(tempDc.Hdc))
                {
                    using (PaintScrollBarTrackEventArgs te =
                               new PaintScrollBarTrackEventArgs(
                                   g,
                                   trackRect,
                                   direction,
                                   bEnabled))
                    {
                        Graphics  ge   = te.Graphics;
                        Rectangle rect = te.TrackRectangle;

                        Color baseColor = GetGray(Color.Blue);

                        ControlPaintEx.DrawScrollBarTrack(
                            ge, rect, baseColor, Color.White, te.Orientation);
                        //paint.OnPaintScrollBarTrack(te);
                    }

                    arrowDirection = bHorizontal ?
                                     ArrowDirection.Left : ArrowDirection.Up;

                    using (PaintScrollBarArrowEventArgs te =
                               new PaintScrollBarArrowEventArgs(
                                   g,
                                   topLeftArrowRect,
                                   topLeftArrowState,
                                   arrowDirection,
                                   direction,
                                   bEnabled))
                    {
                        paint.OnPaintScrollBarArrow(te);
                    }

                    arrowDirection = bHorizontal ?
                                     ArrowDirection.Right : ArrowDirection.Down;

                    using (PaintScrollBarArrowEventArgs te =
                               new PaintScrollBarArrowEventArgs(
                                   g,
                                   bottomRightArrowRect,
                                   bottomRightArrowState,
                                   arrowDirection,
                                   direction,
                                   bEnabled))
                    {
                        paint.OnPaintScrollBarArrow(te);
                    }

                    using (PaintScrollBarThumbEventArgs te =
                               new PaintScrollBarThumbEventArgs(
                                   g,
                                   thumbRect,
                                   thumbState,
                                   direction,
                                   bEnabled))
                    {
                        paint.OnPaintScrollBarThumb(te);
                    }
                }

                NativeMethods.BitBlt(
                    hdc,
                    0,
                    0,
                    bounds.Width,
                    bounds.Height,
                    tempDc.Hdc,
                    0,
                    0,
                    TernaryRasterOperations.SRCCOPY);
            }
            finally
            {
                NativeMethods.ReleaseDC(maskHWnd, hdc);
                tempDc.Dispose();
            }
        }
        private void DrawScrollBar(
            IntPtr maskHWnd,
            Rectangle bounds,
            Rectangle trackRect,
            Rectangle topLeftArrowRect,
            Rectangle bottomRightArrowRect,
            Rectangle thumbRect,
            ControlState topLeftArrowState,
            ControlState bottomRightArrowState,
            ControlState thumbState,
            Orientation direction)
        {
            bool bHorizontal = direction == Orientation.Horizontal;
            ArrowDirection arrowDirection;
            bool bEnabled = _owner.Enabled;
            IScrollBarPaint paint = _owner as IScrollBarPaint;

            if (paint == null)
            {
                return;
            }

            ImageDc tempDc = new ImageDc(bounds.Width, bounds.Height);
            IntPtr hdc = NativeMethods.GetDC(maskHWnd);
            try
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromHdc(tempDc.Hdc))
                {
                    using (PaintScrollBarTrackEventArgs te =
                        new PaintScrollBarTrackEventArgs(
                        g,
                        trackRect,
                        direction,
                        bEnabled))
                    {
                        paint.OnPaintScrollBarTrack(te);
                    }

                    arrowDirection = bHorizontal ?
                        ArrowDirection.Left : ArrowDirection.Up;

                    using (PaintScrollBarArrowEventArgs te =
                        new PaintScrollBarArrowEventArgs(
                        g,
                        topLeftArrowRect,
                        topLeftArrowState,
                        arrowDirection,
                        direction,
                        bEnabled))
                    {
                        paint.OnPaintScrollBarArrow(te);
                    }

                    arrowDirection = bHorizontal ?
                        ArrowDirection.Right : ArrowDirection.Down;

                    using (PaintScrollBarArrowEventArgs te =
                        new PaintScrollBarArrowEventArgs(
                        g,
                        bottomRightArrowRect,
                        bottomRightArrowState,
                        arrowDirection,
                        direction,
                        bEnabled))
                    {
                        paint.OnPaintScrollBarArrow(te);
                    }

                    using (PaintScrollBarThumbEventArgs te =
                        new PaintScrollBarThumbEventArgs(
                        g,
                        thumbRect,
                        thumbState,
                        direction,
                        bEnabled))
                    {
                        paint.OnPaintScrollBarThumb(te);
                    }
                }

                NativeMethods.BitBlt(
                    hdc,
                    0,
                    0,
                    bounds.Width,
                    bounds.Height,
                    tempDc.Hdc,
                    0,
                    0,
                    TernaryRasterOperations.SRCCOPY);
            }
            finally
            {
                NativeMethods.ReleaseDC(maskHWnd, hdc);
                tempDc.Dispose();
            }
        }
示例#5
0
        private void DrawTrackBar(IntPtr hWnd)
        {
            ControlState state = ControlState.Normal;
            bool horizontal = base.Orientation == Orientation.Horizontal;
            ImageDc tempDc = new ImageDc(base.Width, base.Height);
            RECT trackRect = new RECT();
            RECT thumbRect = new RECT();

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

            NativeMethods.SendMessage(
                hWnd, TBM.TBM_GETCHANNELRECT, 0, ref trackRect);
            NativeMethods.SendMessage(
                hWnd, TBM.TBM_GETTHUMBRECT, 0, ref thumbRect);

            Rectangle trackRectangle = horizontal ?
                trackRect.Rect :
                Rectangle.FromLTRB(
                trackRect.Top, trackRect.Left,
                trackRect.Bottom, trackRect.Right);

            if (ThumbHovering(thumbRect))
            {
                if (Helper.LeftKeyPressed())
                {
                    state = ControlState.Pressed;
                }
                else
                {
                    state = ControlState.Hover;
                }
            }

            using (PaintEventArgs pe = new PaintEventArgs(
                g, ClientRectangle))
            {
                OnRenderBackground(pe);
            }

            int ticks = NativeMethods.SendMessage(
                hWnd, TBM.TBM_GETNUMTICS, 0, 0);

            if (ticks > 0)
            {
                List<float> tickPosList = new List<float>(ticks);

                int thumbOffset = horizontal ?
                    thumbRect.Rect.Width : thumbRect.Rect.Height;
                int trackWidth = trackRect.Right - trackRect.Left;
                float tickSpace = (trackWidth - thumbOffset) / (float)(ticks - 1);
                float offset = trackRect.Left + thumbOffset / 2f;

                for(int pos = 0; pos < ticks; pos ++)
                {
                    tickPosList.Add(offset + tickSpace * pos);
                }

                using (PaintTickEventArgs pte = new PaintTickEventArgs(
                    g, trackRectangle, tickPosList))
                {
                    OnRenderTick(pte);
                }
            }

            using (PaintEventArgs pe = new PaintEventArgs(
                g, trackRectangle))
            {
                OnRenderTrack(pe);
            }

            using (PaintThumbEventArgs pe = new PaintThumbEventArgs(
                g, thumbRect.Rect, state))
            {
                OnRenderThumb(pe);
            }

            g.Dispose();
            IntPtr hDC = NativeMethods.GetDC(hWnd);
            NativeMethods.BitBlt(
                hDC, 0, 0, base.Width, base.Height,
                tempDc.Hdc, 0, 0, 0xCC0020);
            NativeMethods.ReleaseDC(hWnd, hDC);
            tempDc.Dispose();
        }