Search code examples
c#winformstrackbar

Change background of the thumb of Trackbar


Is any way to change the background of the thumb of Trackbar? I use C# winform.
Only the background of the Trackbar can be changed, so how can I change or set something in the thumb?

Any answer appreciated.


Solution

  • I saw the project:

    http://www.codeproject.com/Articles/7974/A-variation-on-the-default-TrackBar

    And add the Picture of it to let user choose:

        /// <summary>
        /// Set Image of Trackbar's thumb
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [Description("Set the picture of the thumb")]
        [Category("Image")]
        public Image Picture
        {
            set
            {
                myPic = value;
            }
            get { return myPic; }
        }
    

    And use TextureBrush to let the picture People shoose be an ImageBrush:

     TextureBrush newBrush = new TextureBrush(myPic);
     if (myPic != null)
     {
          g.FillRegion(newBrush, new Region(PaintPath));
          newBrush.Dispose();
     }
     else
     {
          g.FillRegion(bgBrush, new Region(PaintPath));
          bgBrush.Dispose();
     }
    

    There is only one problem that the imagebrush is tile style,

    if I let it not a tile style, it may resolve my questrion.