-1

I am trying to get the background image fot the trackbar only. I used following snippet but the image is not visible.

  public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }[enter image description here][1]

    private void trackBar1_Scroll(object sender, EventArgs e)
    {
        //this.trackBar1.
        this.trackBar1.BackgroundImage = 
                       Image.FromFile(@"C:\Users\310276521\Documents\Aftab\Untitled.jpg");
    }
}

I want to implement this kind of layout:

enter image description here

TaW
  • 53,122
  • 8
  • 69
  • 111
  • This will not work with a TrackBar, even if you [allow transparency](http://stackoverflow.com/questions/9358500/making-a-control-transparent). You would have to turn on ControlStyles.UserPaint and paint everything, i.e. all ticks and the handle yourself! – TaW Apr 07 '17 at 09:48
  • Thank you Sir. I am editing with the feature that I want to be implemented with the help of image.The pointer should point to different color sections/blocks for a paticular mark on the scale when respective event happens and the pointer should move back and forth.Please tell me is it possible to do in WinForms. – Aftab Momin Apr 07 '17 at 10:12
  • You will be interested to look into [this discussion](https://www.pcreview.co.uk/threads/trackbar-with-transparent-background.2251263/) - It boils down to _The trick is to derive a class from System.Windows.Forms.TrackBar, override WndProc and implement the WM_PAINT message yourself_ - So it is possible but a bit tough for beginners. You do realize that TrackBar is an interactive control which lets the user input values? For mere display use the Progressbar. But it too needs to be extended to allow styling. – TaW Apr 07 '17 at 10:15
  • Thank you Sir . Please have a look at a editted version of my question which has the second image showing what i need. – Aftab Momin Apr 07 '17 at 10:22
  • A really simple workaround is to make the trackbar really slim and place it in a Panel which shows the color scale. Or use a moveable Label with a few properties if you need a Value and Min&Max values.. – TaW Apr 07 '17 at 10:46
  • If you need 11 blocks of color consider placing 11 Labels with those BackColors into a FlowLayoutPanel. The Enter events will fire whenever the Mouse enter one of them; use a common event code and cast the `sender as Label`. – TaW Apr 07 '17 at 10:59
  • Thank you. Is it possible to place trackbar inside panel.Also if I use label placed besides each other how exactlythe trackbar will be synchronized with the labels. – Aftab Momin Apr 07 '17 at 11:04
  • Sure. Move it the and maybe also set its Dock to Bottom. – TaW Apr 07 '17 at 11:05
  • Thank you. Is it possible to place trackbar inside panel.Also if I use label placed besides each other how exactlythe trackbar will be synchronized with the labels – Aftab Momin Apr 07 '17 at 11:06

1 Answers1

-1

try this

private void trackBar1_Scroll(object sender, EventArgs e)
{
    //this.trackBar1.
    this.trackBar1.BackgroundImage = Image.FromFile(@"C:\\Users\\310276521\\Documents\\Aftab\\Untitled.jpg");
}

Please make sure you are having the image in that location

Naveen K N
  • 180
  • 1
  • 11
  • If that is not working, remove @ before the path and try. Please post your output here so that it will be useful for future reference – Naveen K N Apr 07 '17 at 09:22
  • Thank you.I did it but I am not getting any image within the trackbar area thats what I need.Also the image which I want to be in background is simply a strip/rectangular box consisting of sub-section which will correspond to each precision of trackbar.Is it possible to do it.Please help – Aftab Momin Apr 07 '17 at 09:44