Problem w. Focus()

  • Thread starter Thread starter Robert Wachtel
  • Start date Start date
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
 
....oops, after investigating more into this I realised that this is a FAQ,
so please ignore this thread.

Sorry!

Greetings from Cologne

Robert
 
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
 
Back
Top