c# - how to bind the button content where mouse selection is start -
<window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:class="storyboard.clear" x:name="window" title="clear" width="640" height="480"> <grid x:name="layoutroot"> <button x:name="btn_a" content="a" height="56" margin="208,149,0,0" verticalalignment="top" horizontalalignment="left" width="75" click="btn_a_click" /> <textbox x:name="txt_display" height="50" margin="208,57,252,0" textwrapping="wrap" verticalalignment="top"/> <button x:name="btn_b" content="b" height="56" margin="297,149,252,0" verticalalignment="top" click="btn_b_click" /> </grid> public partial class clear : window { public clear() { this.initializecomponent(); } private void btn_a_click(object sender, routedeventargs e) { txt_display.text += btn_a.content.tostring(); txt_display.selectionstart = txt_display.text.length; txt_display.focus(); } private void btn_b_click(object sender, routedeventargs e) { txt_display.text += btn_b.content.tostring(); txt_display.selectionstart = txt_display.text.length; txt_display.focus(); } } 
here want bind button content mouse selection starting above figure.
but can't resolve scenario.
please me.
not sure if understand question, trying insert content of button @ cursor location in textbox? if that's case, need caret index of textbox determine insert.
private void btn_a_click(object sender, routedeventargs e) { var caretindex = txt_display.caretindex; txt_display.text =txt_display.text.insert(caretindex, btn_a.content.tostring()); txt_display.selectionstart = txt_display.text.length; txt_display.focus(); }
Comments
Post a Comment