i want to create a control from a form where i have login textbox and password textbox, and login button. when i will enter the active directory account name and its password i
So you have a form with ComboBox filled with account names, a TextBox for password input, and a Button for opening the new form.
Set the TextBox's property PasswordChar
to desired mask character:
textBox1.PasswordChar = '*';
Create a new click method for your login-button by double clicking it in the designer. It should create a new handler:
private void loginButton_Click(object sender, EventArgs e)
{
// Check if the user haven't chosen an account
if (comboBox1.Text == "") { return; }
// Check if the password TextBox is empty
if (textBox1.Text == "") { return; }
// Create a new method for checking the account and password, which returns a bool
bool loginSuccess = CheckUserInput(comboBox1.Text.Trim(), textBox1.Text);
if (loginSuccess)
{
// Create a new instance of your user-interface form. Give the account name and password
// to it's constructor
UserForm newForm = new UserForm(comboBox1.Text.Trim(), textBox1.Text.Trim()))
// Show the created UserForm form
newForm.Show();
// Close this login form
this.Close();
}
}
Edit your UserForm form constructor to take 2 string parameters:
public UserForm(string accountName, string accountPassword)
{
InitializeComponent();
// ...
}
Adding the 2 string parameters is optional. Hope this answered your question.
Example of "CheckUserInput":
private bool CheckUserInput(string account, string password)
{
// your conditions...
return true;
}