Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable selected text moving by mouse press in TextBox?

Tags:

c#

wpf

textbox

I need to create a TextBox that only accept numbers between 1 and 60. My problem is the user can drag the selected text and move. This can create incorrect result.

Here is a gif that show the problem:

Can someone say a method which I can use to disable this functionality.

like image 999
Ilyés Norbert Avatar asked Nov 06 '22 16:11

Ilyés Norbert


1 Answers

You say textbox, but even your gif shows a numeric up down. Using a numeric up down, you can set a max and min which will cap at max once it loses focus, such as clicking a button. Therefore, any functionality you want to use the numeric up down value for will update the value first, then run the rest of the program. If you want to completely prevent the drop all together, you can set AllowDrop to false.

like image 53
William V. Avatar answered Nov 09 '22 22:11

William V.