C# run W/gtk ON/(mono + Linux.Mint)
环境
atom , 代码编辑器 + build 插件;
Linux mint,操作系统;
sudo apt install monodevelop 安装mono开发包
安装gtk3

atom 配置文件
cmd: "mcs -pkg:gtk-sharp-3.0"
name: "CS mono Compiler"
args:
- "{FILE_ACTIVE} &&"
- "mono {FILE_ACTIVE_PATH}/{FILE_ACTIVE_NAME_BASE}.exe"
sh: true,
cwd: /{FILE_ACTIVE_PATH}
程序功能
- 初始显示

- 按 Count 后计数显示增加; 文本框ABCD可输入其它字会,Count后显示在Label2上。
程序代码
namespace GtkSamples {
using Gtk;
using Gdk;
using System;
public class HelloWorld {
static Label label1;
static Label label2;
static Button button1;
static Button button2;
static Entry text1;
static int count = 0;
static void Window_Delete (object obj, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
static void Button1_Clicked ()
{
count++;
label1.Text = count.ToString();
label2.Text = text1.Text;
}
static void Button2_Clicked ()
{
Application.Quit ();
}
public static int Main (string[] args)
{
Application.Init ();
Gtk.Window win = new Gtk.Window ("Mono Gtk# Hello World");
win.DefaultSize = new Gdk.Size (600, 300);
win.DeleteEvent += new DeleteEventHandler (Window_Delete);
label1 = new Label ("0");
label2 = new Label ("Label2");
button1 = new Button ("Count");
button2 = new Button ("Quit");
text1 = new Entry("ABCD");
button1.Clicked += delegate { Button1_Clicked (); };
button2.Clicked += delegate { Button2_Clicked (); };
VBox box = new VBox (true, 8);
box.Add (label1); box.Add (label2); box.Add (button1);
box.Add (text1); box.Add (button2);
win.Add (box);
win.ShowAll ();
Application.Run ();
return 0;
}
}
}
特征:C#对gtk进行了简化,更加OO了,label.Text 也能用上。初始化、布局器外,其它地方基本上都被 C# 化了。
运行结果

C#语言还是不错的,在Linux上用也还不错。
相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36