返回介绍

Introduction to Mono Winforms

发布于 2025-02-22 22:19:37 字数 4150 浏览 0 评论 0 收藏 0

The first part of the Mono Winforms tutorial introduces the Mono platform and the Winforms library.

About this tutorial

This is Mono C# Winforms tutorial. Mono Winforms tutorial is for beginner programmers. The goal of this tutorial is to teach readers basics of GUI programming in Mono Winforms. The tutorial is created and tested on Linux. Nevertheless, it can be used on other operating systems as well. Most examples should run without modification. Images used in this tutorial can be downloaded here .

Mono

The Mono Project is an open development initiative sponsored by Xamarin to develop an open source, UNIX version of the Microsoft .NET development platform. It is a .NET compatible set of tools, which include C# compiler, Common Language Runtime, ADO.NET, ASP.NET and Winforms libraries.

Mono can be divided into three groups:

  • Core components
  • Gnome development stack
  • Microsoft compatibility stack

The core components are the C# language and the Common language runtime. The Gnome development stack includes the GTK# library and various database connectivity libraries. Finally the Microsoft compatibility stack includes the ADO.NET, ASP.NET and the Winforms libraries.

Mono is multiplatform programming platform. It can be run on Linux, BSD, Mac OS X, Solaris and Windows operating systems. It is a multilanguage effort. For now, only C# language is fully supported. Languages like Visual Basic or IronPython are not yet finished.

Winforms

Windows Forms is a graphical user interface application programming interface (API) included as a part of Microsoft's .NET Framework. As of 13 May 2008, Mono's System.Windows.Forms 2.0 is API complete. Simply put, Winforms is a library for creating GUI applications.

Compiling examples

Our tutorial uses the C# language. To compile all the examples in this tutorial, we use the gmcs compiler. The gmcs compiler implements the complete C# 2.0 specification including generics. C# source files must end with a .cs extension.

$ gmcs --about
The Mono C# compiler is (C) 2001-2008, Novell, Inc.
The compiler source code is released under the terms of the GNU GPL
For more information on Mono, visit the project Web site
   http://www.mono-project.com
The compiler was written by Miguel de Icaza, Ravi Pratap, Martin Baulig, 
Marek Safar, Raja R Harinath, Atushi Enomoto

We have a simple C# source file. We will discuss the source later. For now, we concentrate on the compilation process.

simple.cs

using System.Windows.Forms;
using System.Drawing;

public class Simple : Form
{
  public Simple()
  {
     Text = "Simple";
     Size = new Size(250, 200);
     CenterToScreen();
  }

  static public void Main()
  {
     Application.Run(new Simple());
  }
}

C# applications use modules called assemblies. The Mono C# compiler by default only references three assemblies: mscorlib.dll, System.dll and System.Xml.dll. Any additional assembly must be specified with a command line option of the compiler. In our simple example, we need System.Windows.Forms.dll and System.Drawing.dll assemblies.

 gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll simple.cs

Here we compile the simple.cs source file. If the output file name is not specified, we get the exe file with name equal to the source file name. In our example, simple.exe file.

 gmcs -r:System.Windows.Forms.dll -r:System.Drawing.dll simple.cs -out:simpleexample.exe

Here we specify the output file name. We compile source file and get simpleexample.exe file.

Reference

This was an introduction to the Mono Winforms library.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文