浅谈C#开发WinForm

开发 后端
这里介绍如何在C#开发WinForm中加入一个组件,如果你想在窗体中加入任何组件,首先,你必须要初始化这个组件(见下面程序中初始化Label一样)。

本例子主要是介绍如何在 C#开发WinForm中加入一个组件,如果你想在窗体中加入任何组件,首先,你必须要初始化这个组件(见下面程序中初始化Label一样)。并且使用"Controls.Add"方法加入到窗体中,以下是程序运行的界面和源代码。

C#开发WinForm源程序:

 

using System ;  
using System.Windows.Forms ;  
using System.Drawing ;  
public class Form3 : Form  
{  
//定义一个标签  
private Label label1 ;  
public static void Main( )  
{  
Application.Run( new Form3( ) ) ;  
}  
// 构造  
public Form3( )  
{  
// 建立标签并且初始化  
this.label1 = new System.Windows.Forms.Label( ) ;  
//先继承一个Label 类  
label1.Location = new System.Drawing.Point( 24 , 16 ) ;  
//设定 Label的显示位置  
label1.Text = "这是一个WinForm中的标签";  
label1.Size = new System.Drawing.Size ( 200, 50 );  
//设定标签的大小  
label1.TabIndex = 0 ;  
label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;  
// 设定标签的对齐方式  
this.Text = "在WinForm中加入一个标签!";  
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;  
this.AutoScaleBaseSize = new System.Drawing.Size( 8 , 16 ) ;  
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;  
// 设定窗体的边界类型  
this.ForeColor = System.Drawing.SystemColors.Desktop;  
this.Font = new System.Drawing.Font ("宋体", 10 , System.Drawing.FontStyle.Bold ) ;  
// 设定字体、大小就字体的式样  
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;  
this.BackColor = System.Drawing.Color.Blue;  
// 设定背景色  
this.ClientSize = new System.Drawing.Size( 250 , 250 ) ;  
//把标签加到窗体中  
this.Controls.Add ( this.label1 ) ;  
}  

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.

 

以上是对用Visual C#开发WinForm应用程序进行了着重的介绍,由于在.Net FrameWork Sdk中的System.Windows.Froms名称空间中封装了许多关于界面设计的Class(类)。本文只能了解一下Visual C#的强大功能和丰富的开发资源。要想充分利用Visual C#的强大功能,就必须了解并掌握.Net Class Library。也只有掌握了.Net Class Library,你所开发的.Net程序功能才会强大,生命力才更强。

【编辑推荐】

  1. 浅谈C# Connection对象
  2. C#实现PrintPage方法
  3. 利用Visual C#和C#语言特性
  4. C#管道技术学习经验
  5. 概述C#复合控件构建
责任编辑:佚名 来源: 博客园
相关推荐

2009-08-20 09:30:03

C#开发WinForm

2009-09-11 10:41:20

C# WinForm控

2009-04-01 16:26:06

LabelWinFormC#

2011-09-21 10:56:31

C#结构

2009-08-20 18:30:33

C# ReaderWr

2009-08-31 09:37:09

C# Employee

2009-08-12 11:24:25

C# String对象

2009-08-19 17:12:18

C# Connecti

2009-08-07 11:26:53

C#数组结构

2009-08-14 17:58:05

C#接口方法

2009-08-26 13:15:38

C#选择控制

2009-08-26 15:46:01

C#匿名类型

2009-08-25 16:16:43

C# oledbcon

2009-08-06 15:30:23

C#类型系统

2009-09-02 15:41:21

C# HTTPWebR

2009-09-11 11:33:58

C# WinForm控Attribute

2009-09-11 12:31:15

C# WinForm控设置默认值

2009-09-11 12:07:12

C# WinForm控

2009-08-24 16:37:41

C# Winform刷

2009-08-10 10:04:25

C#抽象类C#接口
点赞
收藏

51CTO技术栈公众号