Windows Form, how to await for user input in a constructor.
I have the following code for my MainForm
This is what my LoginCode looks like
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?
21 Replies
you're not supposed to do user input in the ctor
it's a bad practice
hmm i should of guessed as much
I originally had it such that LoginForm would make a new MainForm with the Client
But I don't like how the Forms work out, it can't exit my LoginForm, I can only hide it.
there is the Close method in Form
what happend if you use that ?
Lemmie try that
winforms is pretty raw, either you make
client
a public field and read it from MainForm, or you make your own service to manage a context@xtreit how do I keep my MainForm from closing when I close LoginForm?
🤔
how did you do it ?
My code now looks like this
I don't know 🤔
This is what's weird, isn't MainForm only a local thingy in LoginForm, so what happens to it when I close it
Use Load for stuff that like instead of the ctor
Or whatever the event is called
what's this
new MainForm(client).MainForm_Load();
and should be the flow?
main creates login as modal?
login starts and then it creates main?Erm, you don't call Load
The UI framework does
It was just a place holder
same with load
idk the right funny functions
So the problem I have now is idk how to transfer control to MainForm
I start with LoginForm, which has this code
I want to close LoginForm and open MainForm without any shenanigans
Don't use async void unless it's an event handler
Always use async Task if you can
it is an event handler, or at least i treat it like it is
I mean it's directly subscribed to an event
That's pretty much the only time you use async void
yeh, anyways
whatever form is visible is usable
there shouldn't be problems
it won't close properly though >:(
why is not 'proper' yet