可以看到左边解决方案的下面多了一个项目GtkTest,编译此项目,运行后得到如下界面

上面的界面有点简单,下面加以改进,点击查看-》属性和工具栏,即打开工具栏和熟悉窗口,下面是一部份工具栏窗口,可以适当的修改窗体界面,通过工具栏。

修改后界面如下:

代码如下:
using System; using Gtk; public partial class MainWindow : Gtk.Window { public MainWindow () : base(Gtk.WindowType.Toplevel) { Build (); } protected void OnDeleteEvent (object sender, DeleteEventArgs a) { Application.Quit (); a.RetVal = true; } //打开日志进行查看 protected virtual void OnOpen (object sender, System.EventArgs e) { // Reset the logTreeView and change the window back to original size int width, height; this.GetDefaultSize( out width, out height ); this.Resize( width, height ); LogView.Buffer.Text = ""; // Create and display a fileChooserDialog FileChooserDialog chooser = new FileChooserDialog( "Please select a logfile to view ...", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept ); if( chooser.Run() == ( int )ResponseType.Accept ) { // Open the file for reading. System.IO.StreamReader file = System.IO.File.OpenText( chooser.Filename ); // Copy the contents into the logTextView LogView.Buffer.Text = file.ReadToEnd(); // Set the MainWindow Title to the filename. this.Title = "Nate's Log Viewer -- " + chooser.Filename.ToString(); // Make the MainWindow bigger to accomodate the text in the logTextView this.Resize( 640, 480 ); // Close the file so as to not leave a mess. file.Close(); } // end if chooser.Destroy(); } //关闭应用程序 protected virtual void OnCloseActivated (object sender, System.EventArgs e) { Application.Quit(); } 如果要开发出更加复杂的图形界面在linux上,还得继续研究GTK#,不过总体思路和winform开发一致。 |
