views:

126

answers:

1

i would like to allow the user to play around with the size of the trackbar in vb.net. is there an easy way to do this?

i want to clarify that i would like the user to be able to just resize the trackbar by dragging it just like in design mode.

+1  A: 

You can assign a new size of the trackbar like this:

TrackBar1.Size = New Point(newwidth, newheight)

One way to handle the user interface you mentioned would be to use mousemove, mouseup, and mousedown events of the trackbar.

When you get a mousemove trackbar event with the left mouse button up, you could change the cursor depending on whether it's near an edge (left-right arrows for left or right edge, up-down arrows for top or bottom edge), near a corner (diagonal arrows), or elsewhere in the middle of the trackbar (4 arrows).

When you get a mousedown trackbar event, save the location. If it's near an edge or corner, you will be stretching the edge or the corner of the trackbar. If it's in the central area, you'll be moving it (if that's an option).

When you get a mousemove trackbar event with the left button down, move and/or resize the trackbar using the trackbar size and location properties. Compare the current location with the one you saved at the mousedown event, and stretch or move that distance. Perform the resize and/or relocate according to the current operation as defined by the location in the previous mousedown event (edge stretch, corner stretch, or move). You can either draw a rectangle or resize the trackbar at this point, whichever looks better to you.

When you get a mouseup event, finalize the operation by setting the new trackbar size and location.

xpda