Hi Gang,
I have two text boxes on a form and if the first text box is
populated, I want to place focus on the second text box at startup.
However, this never seems to work. What am I doing wrong here?
private void frmMain_Activat e(object sender, EventArgs e)
{
if (txtOne.Text != "")
{
this.txtTwo.Foc us();
}
}
private void InitializeCompo nent()
{
this.txtOne = new System.Windows. Forms.TextBox() ;
this.txtTwo = new System.Windows. Forms.TextBox() ;
this.SuspendLay out();
//
// txtOne
//
this.txtOne.Loc ation = new System.Drawing. Point(12, 70);
this.txtOne.Nam e = "txtOne";
this.txtOne.Siz e = new System.Drawing. Size(100, 20);
this.txtOne.Tab Index = 0;
this.txtOne.Tex t = "I\'m full!";
//
// txtTwo
//
this.txtTwo.Loc ation = new System.Drawing. Point(180, 70);
this.txtTwo.Nam e = "txtTwo";
this.txtTwo.Siz e = new System.Drawing. Size(100, 20);
this.txtTwo.Tab Index = 1;
//
// frmMain
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F,
13F);
this.AutoScaleM ode =
System.Windows. Forms.AutoScale Mode.Font;
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.txtTwo) ;
this.Controls.A dd(this.txtOne) ;
this.Name = "frmMain";
this.Text = "Form1";
this.Load += new
System.EventHan dler(this.frmMa in_Activate);
this.ResumeLayo ut(false);
this.PerformLay out();
}
Thanks,
Christian
I have two text boxes on a form and if the first text box is
populated, I want to place focus on the second text box at startup.
However, this never seems to work. What am I doing wrong here?
private void frmMain_Activat e(object sender, EventArgs e)
{
if (txtOne.Text != "")
{
this.txtTwo.Foc us();
}
}
private void InitializeCompo nent()
{
this.txtOne = new System.Windows. Forms.TextBox() ;
this.txtTwo = new System.Windows. Forms.TextBox() ;
this.SuspendLay out();
//
// txtOne
//
this.txtOne.Loc ation = new System.Drawing. Point(12, 70);
this.txtOne.Nam e = "txtOne";
this.txtOne.Siz e = new System.Drawing. Size(100, 20);
this.txtOne.Tab Index = 0;
this.txtOne.Tex t = "I\'m full!";
//
// txtTwo
//
this.txtTwo.Loc ation = new System.Drawing. Point(180, 70);
this.txtTwo.Nam e = "txtTwo";
this.txtTwo.Siz e = new System.Drawing. Size(100, 20);
this.txtTwo.Tab Index = 1;
//
// frmMain
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F,
13F);
this.AutoScaleM ode =
System.Windows. Forms.AutoScale Mode.Font;
this.ClientSize = new System.Drawing. Size(292, 273);
this.Controls.A dd(this.txtTwo) ;
this.Controls.A dd(this.txtOne) ;
this.Name = "frmMain";
this.Text = "Form1";
this.Load += new
System.EventHan dler(this.frmMa in_Activate);
this.ResumeLayo ut(false);
this.PerformLay out();
}
Thanks,
Christian
Comment