I want to get the current cursor position from a WPF TextBox. If a TextBox contains text abhishek and cursor is blinking after abhi then i want that index, so that later after clearing the TextBox programmatically and assigning some other or same text programmatically I want to make the cursor blink just after 4 characters.
I have tried get cursor position like this,
_tempFuncName = txtFunctionName.Text;
_cursorPosition = txtFunctionName.SelectionStart;
_selectionLength = txtFunctionName.SelectionLength;
And set back at some later stage from other event like this,
txtFunctionName.Text = _tempFuncName;
txtFunctionName.SelectionStart = _cursorPosition;
txtFunctionName.SelectionLength = _selectionLength;
Here underscore variables are page level variables.
This code is not working. Is there some other approach?
You can play with caretindex property of a text box
//You can set this property on some event
NumberOfDigits.CaretIndex = textbox.Text.Length;
You just need to add one line to set focus on textbox otherwise everything is working fine.
txtFunctionName.Text = _tempFuncName;
txtFunctionName.SelectionStart = _cursorPosition;
txtFunctionName.SelectionLength = _selectionLength ;
txtFunctionName.Focus();
txtFunctionName.Text = _tempFuncName;
txtFunctionName.SelectionStart = _cursorPosition;
txtFunctionName.SelectionLength = _selectionLength ;
these statements are sufficient enough to do the req thing. i was making mistake in choosing event to write code. Thanks everyone.
For me, setting the focus only didn't help, but scrolling to the caret did.
txt_logArea.Select(txt_logArea.Text.Length, 0);
txt_logArea.ScrollToCaret();
Related
I have a textbox txtZipCode. On the TextChange event, i am populating data in other two textboxes txtState and txtCity. What i want to do is, i want to set the cursor after the Text of txtState.
I am doing txtState.Focus()
but, the cursor is displaying on the left side of the text...i want to set the cursor after the text.
Any Suggestions ?
Thanks in Advance
Try This,
txtState.Attributes["onfocus"] = "javascript:this.setSelectionRange(this.value.length,this.value.length);";
This should help after focus:
txtState.SelectionStart = txtState.Text.Length -1;
txtState.SelectionLength = 0;
how do I edit the properties of the button created after setting the property:
columnUltraGrid.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.EditButton;
I would like to add an image and remove the edges of it or just remove the edges and add a word, but then it would have to resize it. If it is not possible to edit, any idea of how it could be done?
By default, the button will be shown using the OS theme. To be able to set the appearance of the cell button you need first to turn off the OS themes:
this.ultraGrid1.UseOsThemes = DefaultableBoolean.False;
Then you can set the ButtonStyle and CellButtonAppearance of the Override:
e.Layout.Override.CellButtonAppearance.Image = MyImage;
e.Layout.Override.ButtonStyle = UIElementButtonStyle.Borderless;
I have a Created a logwindow in my project in C#
This log window is nothing but a richtexbox. I am appending the lines in RichTextbox whenever a method is called.
What i want is : It should autoscroll down whenever a new line is Appended in the rich text box.
Can anybody tell me how to do it.
thanks
Basically you just have to set the "cursor" to the end of the box by setting the SelectionStart and afterwards tell the control to scroll to the caret (= the selection):
rtfBox.SelectionStart = rtfBox.Text.Length;
rtfBox.ScrollToCaret();
I have a winforms app that initially displays a window with two file dialog boxes, one folder dialog box, and one textbox with some default text in it. I want the default text to be highlighted. I've tried everything I have found with no luck.
Any advice is appreciated.
Regards.
Make sure HideSelection is false on your textbox and use the select method to select the text:
textBox1.HideSelection = false;
textBox1.Select(0, textBox1.Text.Length);
You can use SelectionStart and SelectionLenght
textbox.SelectionStart = 0;
textbox.SelectionLength = textbox.Text.Length;
i want to show steps on how to cook something in winform c# .net as steps. Something like a set of text area would be nice but:
-> list box considers the whole string of one step as one item so user needs to scroll horizontally to view the whole step.
-> datagridview is also not suitable as i want the text to word wrapped.
i also want the user to be able to edit the step.
any suggestions of custom control would be nice.
Maybe a wizard like app would be suitable for you. AFAIK there's no native wizard control in C# but you could implement one using tabs or using one of many in the web.
A multi line text box will do the job great. just take a simple text box and do the following to it, and it will turn to a text area:
TextBox listBoxNewInput = new TextBox();
//Initialize label's property
listBoxNewInput.Multiline = true;
// Add vertical scroll bars to the TextBox control.
listBoxNewInput.ScrollBars = ScrollBars.Vertical;
// Allow the RETURN key in the TextBox control.
listBoxNewInput.AcceptsReturn = true;
// Allow the TAB key to be entered in the TextBox control.
listBoxNewInput.AcceptsTab = true;
// Set WordWrap to true to allow text to wrap to the next line.
listBoxNewInput.WordWrap = true;
listBoxNewInput.Width = 315;
listBoxNewInput.Height = 150;
listBoxNewInput.DoubleClick += new EventHandler(listBoxNewInput_DoubleClick);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(labelInput);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
flowLayoutPanel1.Controls.Add(list
BoxNewInput);