c# - `ScrollToCaret` scrolls to the end of the selected text, how can I scroll to the begining of it? -



c# - `ScrollToCaret` scrolls to the end of the selected text, how can I scroll to the begining of it? -

i trying create selected text visible in text box command after found text via search box.

i tried next code:

string searchtext = "multiple lines of text."; int position = textbox.text.indexof(searchtext); textbox.selectionstart = position; textbox.selectionlength = searchtext.length; textbox.scrolltocaret(); // caret @ end of selected text

scrolltocaret method scrolls end of selected text or lastly line of selected text. if spans multiple lines , height of part bigger height of textbox, part of selected text may remain invisible.

please notice can't set caret selection start because loose highlight on selected text.

how can create sure selected text visible or in other words scroll first line of selected text while keeping highlighted?

[dllimport("user32.dll")] static extern intptr sendmessage(intptr hwnd, uint32 msg, int32 wparam, int32 lparam); int numlines = textbox1.getlinefromcharindex(textbox1.selectionstart); //scroll top sendmessage(textbox1.handle, 0x115, 6, 0); //wm_vscroll //scroll numlines sendmessage(textbox1.handle, 0xb6, 0, numlines); //em_linescroll

c# winforms textbox visibility

Comments

Popular posts from this blog

java - Bypassing "final local variable defined in an enclosing type" -

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -