Can't make a TextBox to get focus - Compact Framework.

  • Thread starter Thread starter Juan Gabriel Del Cid
  • Start date Start date
J

Juan Gabriel Del Cid

// After they are show I call tName.focus() from another

Is your other routine getting called? Why don't you just set the focus here?
Is the focus being set to any other control AFTER you set the focus to
tName?

-JG
 
I have a windows form (compact framework) which has three
hidden controls (label, textbox and listbox) at startup.
The controls are enabled, set visible and shown
programatically but I am not able to get the textbox to
get the focus.

Part of the code is below:

Any idea? Thank you.

Carlos Lozano

private void ShowObjects(bool lTogle)
{
// Show or hide controls depending on lTogle

this.Controls.GetEnumerator().Reset();
int Idx = this.Controls.Count-1, fCtrl = 0;
IEnumerator myEnum = this.Controls.GetEnumerator();
while (Idx >= 0 && fCtrl < 24)
{
// Find all the buttons to hide or show them.
// I also tried sendtoback and bringtofront.

myEnum.MoveNext();
Object myObject = myEnum.Current;
if (myObject.GetType().ToString().EndsWith("aButton"))
{
if (fCtrl < 24)
{
aButton Obj = (aButton) myObject;
if (lTogle)
{
Obj.Show();
Obj.BringToFront();
}
else
{
Obj.Hide();
Obj.SendToBack();
}
Obj.Enabled = lTogle;
fCtrl ++;
}
}
Idx --;
}
lName.Enabled = !lTogle; // Label
tName.Enabled = !lTogle; // TextBox
listBox1.Enabled = !lTogle; // ListBox, yes I am sure.
lName.Visible = !lTogle;
tName.Visible = !lTogle;
listBox1.Visible = !lTogle;
if (lTogle)
{
lName.SendToBack();
tName.SendToBack();
listBox1.SendToBack();
lName.Hide();
tName.Hide();
listBox1.Hide();
}
else
{
lName.BringToFront();
tName.BringToFront();
listBox1.BringToFront();
lName.Show();
tName.Show();
listBox1.Show();
}
// After they are show I call tName.focus() from another
routine.
}
}
 
Back
Top