Unable to close Console Login Window after Successful login #2782
Replies: 5 comments 7 replies
-
You must run it asynchronously. Do the cursor go to the next line after you call |
Beta Was this translation helpful? Give feedback.
-
Try adding Application.Shutdown after Application.RequestStop
…On Tue, 1 Aug 2023, 17:56 GitHubDroid, ***@***.***> wrote:
The following is what I have in my Program.cs and LoginWindow.cs:
-- Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terminal.Gui;
using System.Windows.Forms;
namespace COY_Console
{
class Program : System.Windows.Forms.Form
{
static void Main(string[] args)
{
Terminal.Gui.Application.Init();
//Terminal.Gui.Application.Run();
Terminal.Gui.Application.Run(new LoginWindow());
//System.Console.WriteLine($"Username: {((LoginWindow)Terminal.Gui.Application.Top).usernameText.Text}");
// Before the application exits, reset Terminal.Gui for clean shutdown
Terminal.Gui.Application.Shutdown();
}
}
}
--LoginWindow.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using COY_Console;
using Label = Terminal.Gui.Label;
using Button = Terminal.Gui.Button;
using MessageBox = Terminal.Gui.MessageBox;
using Application = Terminal.Gui.Application;
using Window = Terminal.Gui.Window;
using TextField = Terminal.Gui.TextField;
using Pos = Terminal.Gui.Pos;
using Dim = Terminal.Gui.Dim;
using Forms = System.Windows.Forms;
using Terminal.Gui;
namespace COY_Console
{
public class LoginWindow : Window
{
public TextField usernameText;
public LoginWindow()
{
Title = "Login to COY Console (Ctrl+Q to quit)";
// Create input components and labels
var usernameLabel = new Label()
{
Text = "Username:"
};
usernameText = new TextField("")
{
// Position text field adjacent to the label
X = Pos.Right(usernameLabel) + 1,
// Fill remaining horizontal space
Width = Dim.Fill(),
};
var passwordLabel = new Label()
{
Text = "Password:",
X = Pos.Left(usernameLabel),
Y = Pos.Bottom(usernameLabel) + 1
};
var passwordText = new TextField("")
{
Secret = true,
// align with the text box above
X = Pos.Left(usernameText),
Y = Pos.Top(passwordLabel),
Width = Dim.Fill(),
};
// Create login button
var btnLogin = new Button()
{
Text = "Login",
Y = Pos.Bottom(passwordLabel) + 1,
// center the login button horizontally
X = Pos.Center(),
IsDefault = true,
};
// When login button is clicked display a message popup then Windows Form
btnLogin.Clicked += () => {
if (usernameText.Text == "admin" && passwordText.Text == "password")
{
MessageBox.Query("Logging In", "Login Successful", "Ok");
Application.RequestStop();
System.Windows.Forms.Application.Run(new Form1());
//Application.Run<Wizard>();
//Application.RequestStop();
}
else
{
MessageBox.ErrorQuery("Logging In", "Incorrect username or password", "Ok");
}
//Application.Top.Clear();
};
// Add the views to the Window
Add(usernameLabel, usernameText, passwordLabel, passwordText, btnLogin);
}
}
}
Does this help?
—
Reply to this email directly, view it on GitHub
<#2782 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHO3C5AQPXXVTIO6KDN7623XTEYLXANCNFSM6AAAAAA3AAUOVE>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Winforms and terminal don't play well in same process. I think launching
the winforms window will block the console thread.
You could start the winforms as a separate process with Process.Start?
…On Tue, 1 Aug 2023, 19:54 GitHubDroid, ***@***.***> wrote:
That was actually the first thing I tried. No success.
—
Reply to this email directly, view it on GitHub
<#2782 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHO3C5BXB4UBJQTC3HCNURDXTFGE3ANCNFSM6AAAAAA3AAUOVE>
.
You are receiving this because you commented.Message ID: <gui-cs/Terminal.
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The following seemed to close the LoginWindow. I added the following method:
The newThread.Start calls the above method below:
Does this seem like a feasible way to do it ? So my LoginWindow.cs looks like this:
|
Beta Was this translation helpful? Give feedback.
-
I will try and start a repo. In the meantime I will post the files soon. Stand by. Thanks again for any assistance and insight. |
Beta Was this translation helpful? Give feedback.
-
First let me say this project is impressive and I would like to try and develop on top of it.
I am trying utilize the Console Login. What I am trying to do is display a windows form after login.
The following seems to work for opening a Windows Form after login, but the Console Login Window stays open.
// When login button is clicked display a message popup then Windows Form
btnLogin.Clicked += () => {
if (usernameText.Text == "admin" && passwordText.Text == "password")
{
MessageBox.Query("Logging In", "Login Successful", "Ok");
Application.RequestStop();
Any help or insight would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions