Example #1
0
 /// <summary>
 /// Fires the DrawChannel events
 /// </summary>
 /// <param name="hdc">The device context for graphics operations</param>
 protected virtual void OnDrawChannel(IntPtr hdc)
 {
     Graphics graphics = Graphics.FromHdc(hdc);
     if (((this.OwnerDrawParts & TrackBarOwnerDrawParts.Channel) == TrackBarOwnerDrawParts.Channel) && !this.DesignMode)
     {
         TrackBarDrawItemEventArgs e = new TrackBarDrawItemEventArgs(graphics, this.ChannelBounds, (TrackBarItemState)this.ThumbState);
         if (this.DrawChannel != null)
         {
             this.DrawChannel(this, e);
         }
     }
     else
     {
         if (this.ChannelBounds.Equals(Rectangle.Empty))
         {
             return;
         }
         if (VisualStyleRenderer.IsSupported)
         {
             VisualStyleRenderer vsr = new VisualStyleRenderer("TRACKBAR", (int)NativeMethods.TrackBarParts.TKP_TRACK, (int)TrackBarItemState.Normal);
             vsr.DrawBackground(graphics, this.ChannelBounds);
             graphics.ResetClip();
             graphics.Dispose();
             return;
         }
         ControlPaint.DrawBorder3D(graphics, this.ChannelBounds, Border3DStyle.Sunken);
     }
     graphics.Dispose();
 }
Example #2
0
 /// <summary>
 /// Fires the tick drawing events
 /// </summary>
 /// <param name="hdc">The device context that holds the graphics operations</param>
 protected virtual void OnDrawTicks(IntPtr hdc)
 {
     Graphics graphics = Graphics.FromHdc(hdc);
     if (((this.OwnerDrawParts & TrackBarOwnerDrawParts.Ticks) == TrackBarOwnerDrawParts.Ticks) && !this.DesignMode)
     {
         TrackBarDrawItemEventArgs e = new TrackBarDrawItemEventArgs(graphics, this.ClientRectangle, (TrackBarItemState)this.ThumbState);
         if (this.DrawTicks != null)
         {
             this.DrawTicks(this, e);
         }
     }
     else
     {
         if (this.TickStyle == TickStyle.None)
         {
             return;
         }
         if (this.ThumbBounds.Equals(Rectangle.Empty))
         {
             return;
         }
         Color black = Color.Black;
         if (VisualStyleRenderer.IsSupported)
         {
             VisualStyleRenderer vsr = new VisualStyleRenderer("TRACKBAR", (int)NativeMethods.TrackBarParts.TKP_TICS, ThumbState);
             black = vsr.GetColor(ColorProperty.TextColor);
         }
         if (this.Orientation == Orientation.Horizontal)
         {
             this.DrawHorizontalTicks(graphics, black);
         }
         else
         {
             this.DrawVerticalTicks(graphics, black);
         }
     }
     graphics.Dispose();
 }
Example #3
0
        /// <summary>
        /// Fires the DrawThumb events
        /// </summary>
        /// <param name="hdc">The device context for graphics operations</param>
        protected virtual void OnDrawThumb(IntPtr hdc)
        {
            Graphics graphics = Graphics.FromHdc(hdc);
            graphics.Clip = new Region(this.ThumbBounds);
            if (((this.OwnerDrawParts & TrackBarOwnerDrawParts.Thumb) == TrackBarOwnerDrawParts.Thumb) && !this.DesignMode)
            {
                TrackBarDrawItemEventArgs e = new TrackBarDrawItemEventArgs(graphics, this.ThumbBounds, (TrackBarItemState)this.ThumbState);
                if (this.DrawThumb != null)
                {
                    this.DrawThumb(this, e);
                }
            }
            else
            {
                // Determine the style of the thumb, based on the tickstyle
                NativeMethods.TrackBarParts part = NativeMethods.TrackBarParts.TKP_THUMB;
                if (this.ThumbBounds.Equals(Rectangle.Empty))
                {
                    return;
                }
                switch (this.TickStyle)
                {
                    case TickStyle.None:
                    case TickStyle.BottomRight:
                        part = (Orientation != Orientation.Horizontal) ? NativeMethods.TrackBarParts.TKP_THUMBRIGHT : NativeMethods.TrackBarParts.TKP_THUMBBOTTOM;
                        break;
                    case TickStyle.TopLeft:
                        part = (this.Orientation != Orientation.Horizontal) ? NativeMethods.TrackBarParts.TKP_THUMBLEFT : NativeMethods.TrackBarParts.TKP_THUMBTOP;
                        break;

                    case TickStyle.Both:
                        part = (this.Orientation != Orientation.Horizontal) ? NativeMethods.TrackBarParts.TKP_THUMBVERT : NativeMethods.TrackBarParts.TKP_THUMB;
                        break;
                }
                // Perform drawing
                if (VisualStyleRenderer.IsSupported)
                {
                    VisualStyleRenderer vsr = new VisualStyleRenderer("TRACKBAR", (int)part, ThumbState);
                    vsr.DrawBackground(graphics, this.ThumbBounds);
                    graphics.ResetClip();
                    graphics.Dispose();
                    return;
                }
                else
                {
                    switch (part)
                    {
                        case NativeMethods.TrackBarParts.TKP_THUMBBOTTOM:
                            this.DrawPointerDown(graphics);
                            break;
                        case NativeMethods.TrackBarParts.TKP_THUMBTOP:
                            this.DrawPointerUp(graphics);

                            break;
                        case NativeMethods.TrackBarParts.TKP_THUMBLEFT:
                            this.DrawPointerLeft(graphics);

                            break;
                        case NativeMethods.TrackBarParts.TKP_THUMBRIGHT:
                            this.DrawPointerRight(graphics);

                            break;
                        default:
                            if ((this.ThumbState == 3) || !this.Enabled)
                            {
                                ControlPaint.DrawButton(graphics, this.ThumbBounds, ButtonState.All);
                            }
                            else
                            {
                                // Tick-style is both - draw the thumb as a solid rectangle
                                graphics.FillRectangle(SystemBrushes.Control, this.ThumbBounds);
                            }
                            ControlPaint.DrawBorder3D(graphics, this.ThumbBounds, Border3DStyle.Raised);
                            break;
                    }
                }
            }
            graphics.ResetClip();
            graphics.Dispose();
        }