c# - Selecting all contents of TextBox on clicking it -
i have 1 textbox. on clicking it, contents of textbox should selected. solution this? code have tried is:
<textbox name="questiontitle_textbox" text="question title" previewmousedown="questiontitle_textbox_previewmousedown"/> the function questiontitle_textbox_previewmousedown defined as
private void questiontitle_textbox_previewmousedown(object sender, system.windows.input.mousebuttoneventargs e) { questiontitle_textbox.selectall(); }
this works
<textbox name="questiontitle_textbox" text="question title" gotfocus="questiontitle_textbox_gotfocus" previewmouseleftbuttondown="questiontitle_textbox_previewmouseleftbuttondown"/> and in code behind
private void questiontitle_textbox_previewmouseleftbuttondown(object sender, mousebuttoneventargs e) { textbox tb = (sender textbox); if (tb != null) { if (!tb.isfocused) { e.handled = true; tb.focus(); } } } private void questiontitle_textbox_gotfocus(object sender, routedeventargs e) { textbox tb = (sender textbox); if (tb != null) { tb.selectall(); } }
Comments
Post a Comment