c# - Selecting/Highlighting certain text in textbox -
so have textbox time in it, looks this;
when click in textbox, , click on hr part, this;
it should this;
same goes minutes, when @ min part of textbox this;
it should then;
basically trying create programme select/highlight time you. depending on you've clicked on.
what have tried far this;
what should happen when "select" hr part:
textbox1.selectionstart = 0; // start of selection textbox1.selectionlength = 2; //untill ":" seperates hours minutes
this works, text selected thirth picture.
and part:
textbox1.selectionstart = 3; // start of selection, in case after ":" textbox1.selectionlength = textbox1.text.length; //untill end
i know should able write simple if-statement this.
but problem is, how can check part "cursor" at, in textbox?
with selection start can know cursor @ in textbox.
private void textbox1_mouseclick(object sender, mouseeventargs e) { if (textbox1.selectionstart < 3) { textbox1.selectionstart = 0; textbox1.selectionlength = 2; } else if (textbox1.selectionstart > 2) { textbox1.selectionstart = 3; textbox1.selectionlength = textbox1.text.length; } }
if if-statement true, select text, illustration if selectionstart 0, means @ origin of textbox, first 2 digits highlighted.
it should work 2 if-statements.
c# winforms highlight
No comments:
Post a Comment