wpf - How to get TextBox's line from mouse position? -


i have textbox has many lines of text, it's being update this:

  public void updatemessagebox(textbox textbox, string text)     {         textbox.selectionstart = 0;         textbox.selectionlength = 0;         textbox.selectedtext = string.format("{0:hh:mm:ss }", datetime.now) + text + "\n";         textbox.scrolltohome();     } 

now need text line on mouse middle button clicked right away, not selecting line via left click first.

   private void textbox_previewmousedown(object sender, mousebuttoneventargs e)     {         if (e.changedbutton == mousebutton.middle && e.buttonstate == mousebuttonstate.pressed)         {             e.mousedevice.getposition(textbox) //what next?         }     } 

how can textbox line , it's text mouse position?

xaml

<grid x:name="layoutroot">     <grid.rowdefinitions>         <rowdefinition height="auto" />         <rowdefinition height="auto" />     </grid.rowdefinitions>     <textbox width="300"             height="200"             previewmousedown="textbox_previewmousedown"             text="lorem ipsum dolor sit amet, consectetur adipiscing elit. ut consectetur iaculis enim sed condimentum. nunc vestibulum fermentum fermentum. nam arcu ipsum, vestibulum eu felis a, varius gravida dolor. pellentesque tempor cursus quam, mattis volutpat odio eleifend cursus. morbi placerat auctor aliquam. aliquam erat volutpat. curabitur dictum convallis nibh in ullamcorper. "             textwrapping="wrap" />     <textblock x:name="mytextblock"             grid.row="1"             horizontalalignment="center" /> </grid> 

codebehind

private void textbox_previewmousedown(object sender, mousebuttoneventargs e) {     if (e.changedbutton == mousebutton.middle)     {         var mytextbox = (textbox)sender;          var mycharindex = mytextbox.getcharacterindexfrompoint(mouse.getposition(mytextbox), true);         var mylineindex = mytextbox.getlineindexfromcharacterindex(mycharindex);          var myline = mytextbox.getlinetext(mylineindex);          mytextblock.text = myline;     } } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -