Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF : slider going to exact position

I'm using a slider in a WPF window and I want that when the user clicks somewhere on the track of the slider, the thumb to go to that exact position. Currently, when I click somewhere, the thumb goes towards that position, but not to exactly that position. How can I achieve what I want ?

Edit: An example to better explain what I want: If the thumb is at 10 and I press the mouse down near 100 , I want it to jump to 100 (without passing through other values).

like image 933
TheQuestioner Avatar asked Aug 02 '13 14:08

TheQuestioner


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

you need to set IsMoveToPointEnabled to True: http://msdn.microsoft.com/en-us/library/system.windows.controls.slider.ismovetopointenabled.aspx

Slider.IsMoveToPointEnabled Gets or sets a value that indicates whether the Thumb of a Slider moves immediately to the location of the mouse click that occurs while the mouse pointer pauses on the Slider track.

like image 122
Bolu Avatar answered Oct 08 '22 04:10

Bolu


You should handle slider thumb mouse enter event and define behvior you want.

var thumb = (slider1.Template.FindName("PART_Track", slider) as Track).Thumb;
thumb.MouseEnter += new MouseEventHandler(ThumbMouseEnter);

Then you set position of the thumb in ThumbMouseEnter event hendler. THis will allow you to define any behavior you want.

Very similar question is asked on social.msdn.microsoft.com

like image 23
skkap Avatar answered Oct 08 '22 05:10

skkap