08.06.2024 19:58 Gtk3
Приклад використання віджету SourceView - підсвітка коду

dotnet new consoledotnet add package GtkSharpdotnet add package GtkSourceSharpdotnet runusing Gtk;
class Program
{
public static void Main()
{
Application.Init();
new FirstWindow();
Application.Run();
}
public static void Quit()
{
Application.Quit();
}
}using Gtk;
using GtkSource;
class FirstWindow : Window
{
public FirstWindow() : base("Test")
{
SetDefaultSize(600, 350);
SetPosition(WindowPosition.Center);
DeleteEvent += delegate { Program.Quit(); };
VBox vBox = new VBox();
Add(vBox);
HBox hBox = new HBox();
vBox.PackStart(hBox, false, false, 5);
ScrolledWindow scroll = new ScrolledWindow() { WidthRequest = 400, HeightRequest = 300 };
SourceView sourceView = new SourceView
{
ShowLineNumbers = true,
ShowLineMarks = true
};
sourceView.Buffer.Language = new LanguageManager().GetLanguage("c-sharp");
sourceView.Buffer.Text = @"
//C#
void Test()
{
int[] a = [];
List<string> test = [];
Dictionary<string, int> test2 = [];
for (int i = 0; i < 100; i++)
if (i < 50)
Console.WriteLine(i);
}
";
sourceView.Margin = 3;
scroll.Child = sourceView;
hBox.PackStart(scroll, true, true, 5);
ShowAll();
}
}© accounting.org.ua - 2025