Textbox selecting text inside box

G

Guest

I am using .NET 4.2 and I can't get the textbox select functions to work. I did a simple test - added a textbox to the form than added the following code after initializecomponents is called

Textbox1.selectall();

The text is not selected. Does the textbox have to have focus for the select functions to work. What I am trying to do is create a cursor for a numeric keypad I created.
 
G

Guest

The functions work even if the control doesn't have focus but to be ablte to see the selection you'll have to put the focus on the control

Ex:
textBox1.SelectionStart=0;
textBox1.SelectionLength=textBox1.Text.Length;
textBox1.Focus();
 
G

Guest

When I added the Textbox1.Focus, the focus function returned false. So it could not set the focus. So than than I added
this.SetStyle(System.Windows.Forms.ControlStyles.Selectable,true);
this.UpdateStyles();
textbox1.focus();
My code would not compile because I am using CF and it does not support the SetStyle function.

How do I set focus in CF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top