zoukankan      html  css  js  c++  java
  • GTK# 学习笔记

    Choosing Gtk# or Glade#

    Gtk# looks like Windows Forms and Controls, and Glade# is more like WPF, it can define the widgets in a xml file,  and load it into the application.

    The Gtk# "Hello world"  application.

     using System;
     
    using Gtk;
     
     
    public class GtkHelloWorld {
      
       
    public static void Main() {
         Application.Init();
     
         
    //Create the Window
         Window myWin = new Window("My first GTK# Application! ");
         myWin.Resize(
    200,200);
         
         
    //Create a label and put some text in it.     
         Label myLabel = new Label();
         myLabel.Text 
    = "Hello World!!!!";
              
         
    //Add the label to the form     
         myWin.Add(myLabel);
         
         
    //Show Everything     
         myWin.ShowAll();
         
         Application.Run();   
       }
     }

     compile it with command:

    mcs -pkg:gtk-sharp-2.0 helloword.cs

     To use a glade file:

    // file: glade.cs
    using System;
    using Gtk;
    using Glade;
    public class GladeApp
    {
            
    public static void Main (string[] args)
            {
                    
    new GladeApp (args);
            }
     
            
    public GladeApp (string[] args) 
            {
                    Application.Init();
     
                    Glade.XML gxml 
    = new Glade.XML (null"gui.glade""window1"null);
                    gxml.Autoconnect (
    this);
                    Application.Run();
            }
    }

     compile it with command:

    mcs -pkg:glade-sharp-2.0 -resource:gui.glade glade.cs

     use -resource:gui.glade option to make it as embedded resource. Or just leave it in the file system,

    and use the following code to load it.

    Glade.XML gxml = new Glade.XML ("./gui.glade""window1"null);

     add private member, then they can be used in the program, and can add event handler to catch widget events. 

    [Widget]      
    Button button1;
           
    [Widget]
    Label label1;

    button1.Clicked 
    += OnPressButtonEvent;
                  
    public void OnPressButtonEvent( object  o, EventArgs e)
    {
       Console.WriteLine(
    "Button press");
       label1.Text 
    ="Mono"
    }

     or add the widget events in the glade designer, and add the handler code with the same method name:

    void on_button1_clicked(object o, EventArgs e)
    {
    }
  • 相关阅读:
    寒假作业1
    秋季学习总结
    记叙在人生路上对你影响最大的三位老师
    2019年春季学期第二周作业
    币值转换
    第九周作业
    第八周作业
    第七周作业
    第六周作业
    第五周作业
  • 原文地址:https://www.cnblogs.com/zhongzf/p/1520550.html
Copyright © 2011-2022 走看看