Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to select login button on form load after inserting username and password.

What I have tried:

I tried this.focus(); on form load, but have no response.
Posted
Updated 1-Nov-23 9:03am
v2
Comments
Dave Kreskowiak 1-Nov-23 9:15am    
EDIT: Are you trying to click the button or just give the button the input focus?

Also, how are you interacting with the web page? Using which library?
Member 14833898 2-Nov-23 0:06am    
I am using windows form
Dave Kreskowiak 2-Nov-23 0:26am    
And that didn't answer my questions at all. I was referring to the code you've written and the library you're using to get at the web page.
Member 14833898 6-Nov-23 1:22am    
I tried this code but i put pwd immediately select login button and does not allow to complete your password
here is my code
private void TxtPass_TextChanged(object sender, EventArgs e)
{
if (comboBox1.Text != "" && TxtPass.Text != "")
{
button1.BackColor = Color.Green;
this.ActiveControl = button1;
}
}

In Windows form to set the focus on the login button (as per your scenario), to set focus to a specific button on form load, you can use the ActiveControl property.
C#
private void Form1_Load(object sender, EventArgs e)
{
	// Set focus to the login button
	this.ActiveControl = loginButton;
}
The second option is, under form properties the 'AcceptButton' property can be set to the loginButton in the designer.
 
Share this answer
 
So you're saying you want the user to be able to hit ENTER when the username and password fields are filled in and that performs the login?

Make Login button the default button by setting the Form.AcceptButton property to the button and just diable the button until both the username and password textboxes are filled in:
C#
// You don't need the 'this' reference
AcceptButton = loginButton;
loginButton.Enabled = false;

...

private void TxtPass_TextChanged(object sender, EventArgs e)
{
    if (comboBox1.Text != "" && TxtPass.Text != "")
    {
        loginButton.Enabled = true;        
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900