Home > Uncategorized > Create cross platform #GUI using #GTK

Create cross platform #GUI using #GTK

Screenshot 2018-11-25 at 13.19.03

To skip to the code example, here it is on GitHub;

https://github.com/infiniteloopltd/HelloWorldGTK/

GTK# is an option that is available under Visual Studio for Mac under Other > .NET > GTK# 2.0, and it allows you to create windows-forms like GUIs that work cross platform, using the .NET Core framework. Above is a simple application that shows the user’s current IP address.

using System;
using System.Net;
using Gtk;

public partial class MainWindow : Gtk.Window
{
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();

        WebClient wc = new WebClient();
        var strIP = wc.DownloadString(http://icanhazip.com”);
        label2.Text = strIP;

    }

    protected void OnDeleteEvent(object sender, DeleteEventArgs a)
    {
        Application.Quit();
        a.RetVal = true;
    }
}

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: