C
C#MementoMori

cannot close window

...
M
MementoMori39d ago
M
MementoMori39d ago
i reached limit
P
Pobiega39d ago
cs not C# after the backticks and break it up if its too long, or use $paste
M
MODiX39d ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
M
MementoMori39d ago
ok wait
P
Pobiega39d ago
noone wants to download a .txt file just to read your code
M
MementoMori39d ago
BlazeBin - hrwavucnckji
A tool for sharing your source code with the world!
M
MementoMori39d ago
sorry here it is
P
Pobiega39d ago
Okay, there is a whole pile of wrong here First: don't open new forms in another forms constructor. Especially not your main form. two:
Login loginWindow = new Login();
loginWindow.Show();
loginWindow.Close();
Login loginWindow = new Login();
loginWindow.Show();
loginWindow.Close();
This will open a new form to then immediately close it again
M
MementoMori39d ago
yeah i tried doing .Close() but it dont work for the loginWindow i can only close it from Main um why
P
Pobiega39d ago
Because the main form isnt fully constructed at that point
M
MementoMori39d ago
but it will construct right after Login is closed right
P
Pobiega39d ago
yes, in theory - but with winforms (and probably also WPF) the main form is treated differently it sounds like you should just hide the main form, create and show a login form once the main form has loaded (with the load event), then when the login form is done you can show the main form again HOWEVER this code:
Login loginWindow = new Login();
loginWindow.Show();
loginWindow.Close();
Login loginWindow = new Login();
loginWindow.Show();
loginWindow.Close();
will never work as you want after show, it will not "stop" to wait for you to finish logging in. it will instead move to .Close and close If you want the main forms code to "wait" for the login, you need to use ShowDialog() and then you also dont need to close it yourself
M
MementoMori39d ago
yes i used this ShowDialog() but the thing is the login window wont close unless i press the close button for it i wanted for it to close when the user presses the button for which AttemptLogin runs
P
Pobiega39d ago
And that can be done. if you give your button a DialogResult value
M
MementoMori39d ago
um how do i do that
P
Pobiega39d ago
step 1: add a Loaded event handler to your main form
P
Pobiega39d ago
No description
P
Pobiega39d ago
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var form = new LoginWindow();
var result = form.ShowDialog();

// do something with result here
if (result == true)
{
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var form = new LoginWindow();
var result = form.ShowDialog();

// do something with result here
if (result == true)
{
}
}
P
Pobiega39d ago
in LoginWindows.xaml
No description
P
Pobiega39d ago
private void Button_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
M
MementoMori39d ago
what is thiss
M
MementoMori39d ago
before i could even test this suddenly happened 😭
No description
P
Pobiega39d ago
your program is already running close it before starting a new one
M
MementoMori39d ago
yoo its fixed noww thank youu
L
leowest39d ago
@MementoMori tip, wpf does not work like winform u should learn MVVM and how to navigate instead of opening new window https://www.youtube.com/watch?v=N26C_Cq-gAY&list=PLZnwzjShc0PS1DDfPTW3oLSTsn878a6_P&index=22 might be a bit overwhelming at first for u, since ur new to it.
M
MementoMori39d ago
i will check it out thank you
Want results from more Discord servers?
Add your server
More Posts
Release date of 8.0.3?Hey, I have been struggling with an issue that from what I understand will be solved in 8.0.3. httpRedirecting the native standard output streamI need to call into native code the problem is that it writes some of it's output using stdout. Is iWhere can I find a working library for making a LLVM compiler?I found this library (https://github.com/dotnet/LLVMSharp) that provides extern references for the LCheck value type of extended class instanceI have `BaseClass` and `MyClass : BaseClass`. Using `val is BaseClass` will return true for any obj✅ Am I using NumberFormatInfo properly?I have a list of ca. 400 numbers which I want to convert to percentage strings as part of an endpoin✅ .NET MAUI LayoutI am trying to create a password field with the show icon to the right of the password field, when iGetting an error for an undefined variableHello, I'm a CS major working on a project so I'm still pretty new. I'm getting a CS0165 error on liEnemy following after the player (MONOGAME)Im making a simple game using Monogame in visual studio. I have two sprites drawn on the screen (pinIm having an issue checking for collisions when comparing DateTime objects.I have this function that's supposed to check for collisions with bookings. I am using TimeSpans andclamping how fast a input (as a float) can change.Let’s say my Input X float changes in a amount of time from -1 to 1 (-1, -0.5, 0, 0.5, 1) so as an eIValueResolver won't work with AutoMapperHi guys , hope all of you doing well, I'm recently working on a project where I need to convert a spHelp with concurrency blocking issueI have a small app that runs CPU bound on multiple threads (amount of processors) On one PC it workFrontend not workingI dont really keen on frontend but I think have some knowledge about it would be nice, I'm learning JsonSerializerOptionsTo be continuedC# Dictionary questionHi, if i have a dictionary in C# defined like so: `Dictionary<string, List<int>> test;` and I do `Li✅ Avalonia not showing rows in datagridThere are no rows in my datagrid in Avalonia, the headers are visible. I've checked if my list is emInfinite loop```c# /// ------------------------------------------------------------ /// <summary> /// Creates a sHow to connect my c# backend with the frontend?Hello, I created a ASP NET Core Web Api project with the command dotnet new webapi -minimal. In my ✅ Using `Func<ReadOnlySpan<char>,bool>` but not allowed due to Pointer TypeI am building a parser, and performance is of concern. So instead of allocating infinite strings wheconcurrency and atomicity Asp.net core web api and efcorelet's say there's an endpoint called AssingUser() ,this endpoint assigns one donation to this curren