Linux图形界面开发—monodevelop初探

摘要:
在ubutu10.04下,如果通过源码安装monodevelop有问题,建议用ubuntu自带的软件包管理器安装。下面通过几个例子测试下monodevelop控制台应用程序u强大的界面于windows下的vs差不多。输入项目的名称,保存位置,解决方案的名称,保存位置,与windows下一样的哦,其他设置都默认。编译好后,会生成一个consol.exe的可执行文件,直接F5运行可以得到输出结果也可以通过命令guoyuanwei@localhost:~$mono/home/guoyuanwei/monotest/consol/consol/bin/Debug/consol.exe得到结果HelloWorld!

在ubutu10.04下,如果通过源码安装monodevelop有问题,建议用ubuntu自带的软件包管理器安装。

下面通过几个例子测试下monodevelop

(1)控制台应用程序

uLinux图形界面开发—monodevelop初探第1张

强大的界面于windows下的vs差不多。输入项目的名称,保存位置,解决方案的名称,保存位置,与windows下一样的哦,其他设置都默认。

Linux图形界面开发—monodevelop初探第2张

一切都是那么的熟悉,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,最后生成的界面如下

Linux图形界面开发—monodevelop初探第3张

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

Linux图形界面开发—monodevelop初探第4张

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

Linux图形界面开发—monodevelop初探第5张

修改后界面如下:

Linux图形界面开发—monodevelop初探第6张

代码如下:

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开发一致。

免责声明:文章转载自《Linux图形界面开发—monodevelop初探》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇MeteoInfo-Java解析与绘图教程(四)Python 异步编程下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux c 线程间同步(通信)的几种方法--互斥锁,条件变量,信号量,读写锁

Linux下提供了多种方式来处理线程同步,最常用的是互斥锁、条件变量、信号量和读写锁。 下面是思维导图:  一、互斥锁(mutex)   锁机制是同一时刻只允许一个线程执行一个关键部分的代码。 1 . 初始化锁 int pthread_mutex_init(pthread_mutex_t *mutex,const pthread_mutex_attr_t...

【学习总结】快速上手Linux玩转典型应用-第5章-远程连接SSH专题

课程目录链接 快速上手Linux玩转典型应用-目录 目录 1. 认识SSH 2. 服务器安装SSH服务 3. 客户端安装SSH工具 4. 客户端链接SSH服务 5. SSH config 6. SSH免密登录 ============================================================== =====...

为github帐号添加SSH keys(Linux和Windows)

【gitee里面又非常详细的官方教程】 文章转自:https://blog.cofface.com/archives/406.html/2 一、Linux增加ssh keys方法: 使用git clone命令从github上同步github上的代码库时,如果使用SSH链接(如我自己的cofface_recovery项目:git@github.com:cof...

Linux Tips: 使用dd制作Ubuntu系统的安装盘

找到U盘的分区 sudo fdisk -l 卸载U盘 # 假设U盘的挂载是/dev/sdc1 sudo umount /dev/sdc1 格式化U盘 # 假设U盘是/dev/sdc,注意这里是“sdc”不带“1” sudo mkfs.vfat -I /dev/sdc 写入镜像 # 注意这里也是“sdc”不带“1” sudo dd if...

初识linux

linux: ifconfig = ip add 查看IP 改IP : dhclient(自动获取ip) ip add 静态 vi /etc/sysconfig/networkscripts/ifcfg-ens33 INSERT BOOTPROTO=static onboot =yes IPADDR=ip地址 NETMASK=255.255.255.0...

GTK简单了解记录

GTK+http://zh.wikipedia.org/wiki/GTK%2B#.E5.9B.BE.E5.BD.A2.E6.97.A0.E5.85.B3.E4.BB.A3.E7.A0.81 GTK+最初是GIMP的专用开发库(GIMP Toolkit),后来发展为Unix-like系统下开发图形界面的应用程序的主流开发工具之一。GTK+是自由软件,并且是G...