Windows Develop Bookmark and Share   
 index > Windows Forms General > Using .Focus();
 

Using .Focus();

Hi, I have a question.

I am trying to create a form where people will enter some data and all textboxes mainly are the same and only one box is changing. So I created a form and then a button and and when you cklick this button the data is added to the database and the for is not closing.

When the button "save and add new" is cklicked I need that I textBox to be selected so I used function "serial.Focus();" and here comes my problem - everithing looks and works grate, but the problem is that when the program returns the form focusd on the TextBox serial the whole text that is entered in that TextBox is not selected and I need it to be selected.

Can anyone explane me how to make the form to return and be focused on particular TextBox and all text in that textbox to be highligted?

Here is what I have:

private void savenew_Click(object sender, EventArgs e)

{

try

{

this.serialsTableAdapter.InsertSerial(item.Text, serial.Text, datein.Text, dateout.Text, warant.Text, comm.Text, com.Text);

}

catch

{

MessageBox.Show(this, "Error");

return;

}

serial.Focus();

MessageBox.Show("Data has been added to the database");

return;

Thank you

Levani777  Tuesday, May 01, 2007 7:05 AM

Hi Levani,

Use serial.SelectAll() after serial.Focus()to select all the text in the TextBox Control.

decyclone  Tuesday, May 01, 2007 8:02 AM

Hi Levani,

Use serial.SelectAll() after serial.Focus()to select all the text in the TextBox Control.

decyclone  Tuesday, May 01, 2007 8:02 AM

Thank you for reply. I will try it.

Levani

Levani777  Wednesday, May 02, 2007 10:20 AM

You can use google to search for other answers

Custom Search

More Threads

• Hide form on startup! / Disable the Close Button
• reading comma separated values from .txt
• Cant get drag-n-drop from Excel to work. Please help.
• LinkLabel - AutoEllipsis on and automatic tooltip
• Want to set initialdirectory to the mycomputer
• Screen minimizing automatically
• Unsure of code sequence with MyBase call on inherited control when overriding methods
• How do I dynamically create a new control on a form?
• Saving infromation gained from radiobutton
• how to convert byte array to bitmap in c#