From e8aad38e064f9e76ae001290c5490c2b7e11bc95 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 5 Jul 2024 13:52:03 +0100 Subject: [PATCH] Some adjustments and add comment. --- SelfContained/Program.cs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index 6c4aac778..b723bcbd4 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -15,6 +15,8 @@ public static class Program // Before the application exits, reset Terminal.Gui for clean shutdown Application.Shutdown (); + // To see this output on the screen it must be done after shutdown, + // which restores the previous screen. Console.WriteLine ($@"Username: {ExampleWindow.UserName}"); } } @@ -31,7 +33,7 @@ public class ExampleWindow : Window // Create input components and labels var usernameLabel = new Label { Text = "Username:" }; - var usernameText = new TextField + var userNameText = new TextField { // Position text field adjacent to the label X = Pos.Right (usernameLabel) + 1, @@ -50,7 +52,7 @@ public class ExampleWindow : Window Secret = true, // align with the text box above - X = Pos.Left (usernameText), + X = Pos.Left (userNameText), Y = Pos.Top (passwordLabel), Width = Dim.Fill () }; @@ -68,20 +70,20 @@ public class ExampleWindow : Window // When login button is clicked display a message popup btnLogin.Accept += (s, e) => - { - if (usernameText.Text == "admin" && passwordText.Text == "password") - { - MessageBox.Query ("Logging In", "Login Successful", "Ok"); - UserName = usernameText.Text; - Application.RequestStop (); - } - else - { - MessageBox.ErrorQuery ("Logging In", "Incorrect username or password", "Ok"); - } - }; + { + if (userNameText.Text == "admin" && passwordText.Text == "password") + { + MessageBox.Query ("Logging In", "Login Successful", "Ok"); + UserName = userNameText.Text; + Application.RequestStop (); + } + else + { + MessageBox.ErrorQuery ("Logging In", "Incorrect username or password", "Ok"); + } + }; // Add the views to the Window - Add (usernameLabel, usernameText, passwordLabel, passwordText, btnLogin); + Add (usernameLabel, userNameText, passwordLabel, passwordText, btnLogin); } }