Soggy
Soggy
CC#
Created by Soggy on 12/2/2023 in #help
User Control Eventhandler. How to get my control's components to inherit an Eventhandler.
No description
6 replies
CC#
Created by Soggy on 11/27/2023 in #help
Windows Form, how to await for user input in a constructor.
I have the following code for my MainForm
public partial class MainForm : Form
{
public Client ActiveClient { get; }

public MainForm()
{
LoginForm login = new LoginForm();
this.Hide();
login.Activate();

//ActiveClient = await login.GetClient(); //GetClient() is not a real function in my code

InitializeComponent();
}
}
public partial class MainForm : Form
{
public Client ActiveClient { get; }

public MainForm()
{
LoginForm login = new LoginForm();
this.Hide();
login.Activate();

//ActiveClient = await login.GetClient(); //GetClient() is not a real function in my code

InitializeComponent();
}
}
This is what my LoginCode looks like
public async Task LogIn(string username, string password)
{
if (string.IsNullOrEmpty(username)) { MessageBox.Show("Please enter a username"); return; }
if (string.IsNullOrEmpty(password)) { MessageBox.Show("Please enter a password"); return; }

Task<User.PassCode> passTask = User.PassCode.EncodeAsync(password);
User.PassCode pass = await passTask;
this.UseWaitCursor = true;

Client? client = await Client.Authenticate(User.ID.Parse(username), pass);

if (client == null)
{
MessageBox.Show("Incorrect Username or Password");
return;
}

this.Hide();
this.UseWaitCursor= false;
//new MainForm(client).MainForm_Load();
}
public async Task LogIn(string username, string password)
{
if (string.IsNullOrEmpty(username)) { MessageBox.Show("Please enter a username"); return; }
if (string.IsNullOrEmpty(password)) { MessageBox.Show("Please enter a password"); return; }

Task<User.PassCode> passTask = User.PassCode.EncodeAsync(password);
User.PassCode pass = await passTask;
this.UseWaitCursor = true;

Client? client = await Client.Authenticate(User.ID.Parse(username), pass);

if (client == null)
{
MessageBox.Show("Incorrect Username or Password");
return;
}

this.Hide();
this.UseWaitCursor= false;
//new MainForm(client).MainForm_Load();
}
This gets called when the login button is pressed. Is there a nice way to get the Client from my LoginForm? Any ideas? Am I missing something really simple or is this not possible the way I set it up?
35 replies