mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* touching publish.yml * Moved Examples into ./Examples * Moved Benchmarks into ./Tests * Moved Benchmarks into ./Tests * Moved UICatalog into ./Examples * Moved UICatalog into ./Examples 2 * Moved tests into ./Tests * Updated nuget
This commit is contained in:
88
Examples/Example/Example.cs
Normal file
88
Examples/Example/Example.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
// 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 System;
|
||||
using Terminal.Gui;
|
||||
|
||||
// Override the default configuration for the application to use the Light theme
|
||||
ConfigurationManager.RuntimeConfig = """{ "Theme": "Light" }""";
|
||||
|
||||
Application.Run<ExampleWindow> ().Dispose ();
|
||||
|
||||
// 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}");
|
||||
|
||||
// Defines a top-level window with border and title
|
||||
public class ExampleWindow : Window
|
||||
{
|
||||
public static string UserName;
|
||||
|
||||
public ExampleWindow ()
|
||||
{
|
||||
Title = $"Example App ({Application.QuitKey} to quit)";
|
||||
|
||||
// Create input components and labels
|
||||
var usernameLabel = new Label { Text = "Username:" };
|
||||
|
||||
var 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
|
||||
btnLogin.Accepting += (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");
|
||||
}
|
||||
// Anytime Accepting is handled, make sure to set e.Cancel to false.
|
||||
e.Cancel = false;
|
||||
};
|
||||
|
||||
// Add the views to the Window
|
||||
Add (usernameLabel, userNameText, passwordLabel, passwordText, btnLogin);
|
||||
}
|
||||
}
|
||||
15
Examples/Example/Example.csproj
Normal file
15
Examples/Example/Example.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<!-- Version numbers are automatically updated by gitversion when a release is released -->
|
||||
<!-- In the source tree the version will always be 1.0 for all projects. -->
|
||||
<!-- Do not modify these. -->
|
||||
<AssemblyVersion>2.0</AssemblyVersion>
|
||||
<FileVersion>2.0</FileVersion>
|
||||
<Version>2.0</Version>
|
||||
<InformationalVersion>2.0</InformationalVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Terminal.Gui\Terminal.Gui.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
11
Examples/Example/README.md
Normal file
11
Examples/Example/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Terminal.Gui C# Example
|
||||
|
||||
This example shows how to use the Terminal.Gui library to create a simple GUI application in C#.
|
||||
|
||||
This is the same code found in the Terminal.Gui README.md file.
|
||||
|
||||
To explore the full range of functionality in Terminal.Gui, see the [UICatalog](../UICatalog) project
|
||||
|
||||
See [README.md](https://github.com/gui-cs/Terminal.Gui) for a list of all Terminal.Gui samples.
|
||||
|
||||
Note, the old `demo.cs` example has been deleted because it was not a very good example. It can still be found in the [git history](https://github.com/gui-cs/Terminal.Gui/tree/v1.8.2).
|
||||
Reference in New Issue
Block a user