Linux圖形界面開發—monodevelop初探


在ubutu10.04下,如果通過源碼安裝monodevelop有問題,建議用ubuntu自帶的軟件包管理器安裝。

下面通過幾個例子測試下monodevelop

(1)控制台應用程序

u

強大的界面於windows下的vs差不多。輸入項目的名稱,保存位置,解決方案的名稱,保存位置,與windows下一樣的哦,其他設置都默認。

一切都是那么的熟悉,c#代碼。編譯好后,會生成一個consol.exe的可執行文件,直接F5運行可以得到輸出結果

也可以通過命令guoyuanwei@localhost:~$ mono /home/guoyuanwei/monotest/consol/consol/bin/Debug/consol.exe 得到結果
Hello World!
(2)Gtk#圖形界面的程序

在上面創建的解決方案上,點擊鼠標右鍵-》Add-》Add New Project添加一個新的項目,在彈出的窗口中選擇GTK#2.0,最后生成的界面如下

可以看到左邊解決方案的下面多了一個項目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開發一致。




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM