mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixed Readme
This commit is contained in:
17
README.md
17
README.md
@@ -63,28 +63,32 @@ The team is looking forward to seeing new amazing projects made by the community
|
||||
The following example shows a basic Terminal.Gui application in C#:
|
||||
|
||||
```csharp
|
||||
// This is a simple example application. For the full range of functionality
|
||||
// see the UICatalog project
|
||||
|
||||
// A simple Terminal.Gui example in C# - using C# 9.0 Top-level statements
|
||||
|
||||
using Terminal.Gui;
|
||||
|
||||
Application.Run<ExampleWindow> ();
|
||||
|
||||
System.Console.WriteLine ($"Username: {((ExampleWindow)Application.Top).usernameText.Text}");
|
||||
|
||||
// Before the application exits, reset Terminal.Gui for clean shutdown
|
||||
Application.Shutdown ();
|
||||
|
||||
System.Console.WriteLine ($@"Username: {ExampleWindow.Username}");
|
||||
|
||||
// Defines a top-level window with border and title
|
||||
public class ExampleWindow : Window {
|
||||
public static string Username { get; internal set; }
|
||||
public TextField usernameText;
|
||||
|
||||
|
||||
public ExampleWindow ()
|
||||
{
|
||||
Title = "Example App (Ctrl+Q to quit)";
|
||||
|
||||
// Create input components and labels
|
||||
var usernameLabel = new Label () {
|
||||
Text = "Username:"
|
||||
var usernameLabel = new Label () {
|
||||
Text = "Username:"
|
||||
};
|
||||
|
||||
usernameText = new TextField ("") {
|
||||
@@ -112,7 +116,7 @@ public class ExampleWindow : Window {
|
||||
// Create login button
|
||||
var btnLogin = new Button () {
|
||||
Text = "Login",
|
||||
Y = Pos.Bottom(passwordLabel) + 1,
|
||||
Y = Pos.Bottom (passwordLabel) + 1,
|
||||
// center the login button horizontally
|
||||
X = Pos.Center (),
|
||||
IsDefault = true,
|
||||
@@ -122,6 +126,7 @@ public class ExampleWindow : Window {
|
||||
btnLogin.Clicked += () => {
|
||||
if (usernameText.Text == "admin" && passwordText.Text == "password") {
|
||||
MessageBox.Query ("Logging In", "Login Successful", "Ok");
|
||||
Username = usernameText.Text.ToString ();
|
||||
Application.RequestStop ();
|
||||
} else {
|
||||
MessageBox.ErrorQuery ("Logging In", "Incorrect username or password", "Ok");
|
||||
|
||||
Reference in New Issue
Block a user