C# Windows Forms应用程序描述

开发 后端
这里介绍C# Windows Forms应用程序,以及介绍C#提倡枚举作为定义变量类型的一种方式,而不是指定一个整数范围,这样能维护类型的安全性并能提供尽可能多的信息。

那么,基于C# Windows Forms应用程序是什么样的呢?看一下tic-tac-toe例程吧。一个C# Windows Forms应用程序一开始通过一系列using声明先引入必要的定义(程序需要的类型定义)。

namespace CSharpTicTacToe {  
using System;  
using System.Drawing;  
using System.Drawing.Drawing2D;  
using System.WinForms;  
// Windows Form code goes here?  
}; 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

第一个namespace关键字是可选的。但是对于设定功能的作用范围通常是很有用的——特别是在assembly过程中,一种编写DLL的新方式。在关键字之后,每一个using声明告诉C#编译器,程序所要用到的系统功能。因为tic-tac-toe游戏是一个Windows 窗体,源文件使用了System的WinForms namespace。而且,因为游戏使用了图形,源代码就要引入URT的绘图功能。

在你引用了namespace后,你就要通过从系统提供的Form类继承一个类来表示一个Windows 窗体。

public class CSharpTicTacToe : Form {  
// Windows Form code goes here, including  
// data members, a constructor, and  
// some event handlers?  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

C#提倡枚举作为定义变量类型的一种方式,而不是指定一个整数范围,这样能维护类型的安全性并能提供尽可能多的信息。Tic-tac-toe游戏指定了三种枚举类型:player类型、用于在板上做标记的类型和对板上位置命名的类型。以下就是具体的描述。你可以在游戏的多个地方看到它们的用途。

public enum Player {  
XPlayer,OPlayer  
}  
public enum Mark  
{  
XMark,  
OMark,  
Blank  
}  
public enum Positions  
TopLeft,  
TopCenter,  
TopRight,  
MiddleLeft,  
MiddleCenter,  
MiddleRight,  
BottomLeft,  
BottomCenter,  
BottomRight,  
Unknown  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

以上介绍C# Windows Forms应用程序

【编辑推荐】

  1. C#编写数字转换中文算法
  2. 分析C#调用COM对象
  3. C# SingleInstance类浅析
  4. 概述C#调用Active组件
  5. C# Convert.ToInt32简介
责任编辑:佚名 来源: IT168
相关推荐

2009-08-24 13:30:50

C# Windows

2009-08-24 14:19:27

C# Windows应

2009-08-24 16:02:10

C# Windows应

2009-08-25 09:39:21

创建C# Window

2009-08-24 09:25:18

Visual C# ..NET应用程序

2009-08-06 10:27:08

C#应用程序域

2009-08-24 14:03:19

Windows For

2009-01-19 11:07:42

C#Web.NET

2009-08-28 16:43:08

AutoCAD托管C#

2009-08-13 17:04:09

C#语言C#程序

2009-09-03 17:36:13

C#创建Web应用程序

2009-08-12 18:28:09

C#事件处理程序

2009-08-14 18:04:59

C#Windows应用

2013-05-14 10:33:57

AIR Android应用程序描述文件

2009-07-30 18:50:32

C#发送消息C#应用程序

2022-01-12 06:59:02

C#程序集装载

2009-08-19 15:31:32

C#控制台应用程序

2009-08-14 17:27:30

C#Windows应用

2009-08-14 17:36:20

C#Windows应用

2024-04-28 10:58:00

C#编程窗口关闭事件
点赞
收藏

51CTO技术栈公众号