如何用C#开发WinForm

发布时间:2021-12-02 11:33:54 作者:iii
来源:亿速云 阅读:129

这篇文章主要讲解了“如何用C#开发WinForm”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何用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 ) ;  }  }

感谢各位的阅读,以上就是“如何用C#开发WinForm”的内容了,经过本文的学习后,相信大家对如何用C#开发WinForm这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. C#在Winform开发中使用Grid++报表
  2. 怎么在C#中利用WinForm对DataGridView进行开发

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

winform

上一篇:VB.NET事件六大类分别是什么

下一篇:tk.Mybatis插入数据获取Id怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》