C
Christian Blackburn
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_Activate(object sender, EventArgs e)
{
if (txtOne.Text != "")
{
this.txtTwo.Focus();
}
}
private void InitializeComponent()
{
this.txtOne = new System.Windows.Forms.TextBox();
this.txtTwo = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtOne
//
this.txtOne.Location = new System.Drawing.Point(12, 70);
this.txtOne.Name = "txtOne";
this.txtOne.Size = new System.Drawing.Size(100, 20);
this.txtOne.TabIndex = 0;
this.txtOne.Text = "I\'m full!";
//
// txtTwo
//
this.txtTwo.Location = new System.Drawing.Point(180, 70);
this.txtTwo.Name = "txtTwo";
this.txtTwo.Size = new System.Drawing.Size(100, 20);
this.txtTwo.TabIndex = 1;
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.txtTwo);
this.Controls.Add(this.txtOne);
this.Name = "frmMain";
this.Text = "Form1";
this.Load += new
System.EventHandler(this.frmMain_Activate);
this.ResumeLayout(false);
this.PerformLayout();
}
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_Activate(object sender, EventArgs e)
{
if (txtOne.Text != "")
{
this.txtTwo.Focus();
}
}
private void InitializeComponent()
{
this.txtOne = new System.Windows.Forms.TextBox();
this.txtTwo = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtOne
//
this.txtOne.Location = new System.Drawing.Point(12, 70);
this.txtOne.Name = "txtOne";
this.txtOne.Size = new System.Drawing.Size(100, 20);
this.txtOne.TabIndex = 0;
this.txtOne.Text = "I\'m full!";
//
// txtTwo
//
this.txtTwo.Location = new System.Drawing.Point(180, 70);
this.txtTwo.Name = "txtTwo";
this.txtTwo.Size = new System.Drawing.Size(100, 20);
this.txtTwo.TabIndex = 1;
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F,
13F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.txtTwo);
this.Controls.Add(this.txtOne);
this.Name = "frmMain";
this.Text = "Form1";
this.Load += new
System.EventHandler(this.frmMain_Activate);
this.ResumeLayout(false);
this.PerformLayout();
}
Thanks,
Christian