Problem w. Focus()

R

Robert Wachtel

Hi!

Visual Studio 2005 C# Compact Framework 1 for Pocket PC 2003

I try to set input focus to a TextBox in a TabPage after entering the
TabPage:

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.tabControl1.SelectedIndex == 1)
this.textBox1.Focus();
}

didn't work. So I tried adding an

if (this.tabControl1.SelectedIndex == 1)
{
this.textBox1.Focus();
this.tabControl1.Focus();
this.tabPage1.Focus();
}

but that didn't work either.

I checked with

if (this.textbox1.Focus() == true)
this.textbox1.text = "TEST";

so the TextBox displays "TEST" but does not receive focus?

What am I doing wrong?

Greetings from Cologne

Robert
 
R

Robert Wachtel

....oops, after investigating more into this I realised that this is a FAQ,
so please ignore this thread.

Sorry!

Greetings from Cologne

Robert
 
R

Robert Wachtel

Just for the record:

I solved this with a timer hack:

private void tbctrl_SelectedIndexChanged(object sender, EventArgs e)
{
Application.DoEvents();
tmrFocusControl.Enabled = true;
}

private void tmrFocusControl_Tick(object sender, EventArgs e)
{
tmrFocusControl.Enabled = false;
this.Text = this.tbctrl.TabPages[this.tbctrl.SelectedIndex].Text;
foreach (Control ctrl in
this.tbctrl.TabPages[this.tbctrl.SelectedIndex].Controls)
{
if (ctrl is TextBox)
{
ctrl.Focus();
break;
}
}
}

Timer interval is set to 100.

Greetings from Cologne

Robert
 

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