Visual C#2005程序设计教程

源代码在线查看: form1.cs

软件大小: 4702 K
上传用户: devilgaze
关键词: Visual 2005 程序设计 教程
下载地址: 免注册下载 普通下载 VIP

相关代码

				using System;
				using System.Drawing;
				using System.Collections;
				using System.ComponentModel;
				using System.Windows.Forms;
				using System.Data;
				
				namespace 单选按钮与复选按钮
				{
					/// 
					/// Form1 的摘要说明。
					/// 
					public class Form1 : System.Windows.Forms.Form
					{
						private System.Windows.Forms.RadioButton radioButton1;
						private System.Windows.Forms.RadioButton radioButton2;
						private System.Windows.Forms.Label label1;
						private System.Windows.Forms.Button button1;
						/// 
						/// 必需的设计器变量。
						/// 
						private System.ComponentModel.Container components = null;
				
						public Form1()
						{
							//
							// Windows 窗体设计器支持所必需的
							//
							InitializeComponent();
				
							//
							// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
							//
						}
				
						/// 
						/// 清理所有正在使用的资源。
						/// 
						protected override void Dispose( bool disposing )
						{
							if( disposing )
							{
								if (components != null) 
								{
									components.Dispose();
								}
							}
							base.Dispose( disposing );
						}
				
						#region Windows 窗体设计器生成的代码
						/// 
						/// 设计器支持所需的方法 - 不要使用代码编辑器修改
						/// 此方法的内容。
						/// 
						private void InitializeComponent()
						{
				            this.radioButton1 = new System.Windows.Forms.RadioButton();
				            this.radioButton2 = new System.Windows.Forms.RadioButton();
				            this.label1 = new System.Windows.Forms.Label();
				            this.button1 = new System.Windows.Forms.Button();
				            this.SuspendLayout();
				            // 
				            // radioButton1
				            // 
				            this.radioButton1.AutoSize = true;
				            this.radioButton1.Location = new System.Drawing.Point(61, 89);
				            this.radioButton1.Name = "radioButton1";
				            this.radioButton1.Size = new System.Drawing.Size(88, 19);
				            this.radioButton1.TabIndex = 0;
				            this.radioButton1.Text = "显示日期";
				            // 
				            // radioButton2
				            // 
				            this.radioButton2.AutoSize = true;
				            this.radioButton2.Checked = true;
				            this.radioButton2.Location = new System.Drawing.Point(190, 89);
				            this.radioButton2.Name = "radioButton2";
				            this.radioButton2.Size = new System.Drawing.Size(88, 19);
				            this.radioButton2.TabIndex = 1;
				            this.radioButton2.TabStop = true;
				            this.radioButton2.Text = "显示时间";
				            // 
				            // label1
				            // 
				            this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
				            this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
				            this.label1.Location = new System.Drawing.Point(31, 30);
				            this.label1.Name = "label1";
				            this.label1.Size = new System.Drawing.Size(277, 29);
				            this.label1.TabIndex = 2;
				            // 
				            // button1
				            // 
				            this.button1.Location = new System.Drawing.Point(119, 136);
				            this.button1.Name = "button1";
				            this.button1.Size = new System.Drawing.Size(100, 30);
				            this.button1.TabIndex = 4;
				            this.button1.Text = "显示";
				            this.button1.Click += new System.EventHandler(this.button1_Click);
				            // 
				            // Form1
				            // 
				            this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
				            this.ClientSize = new System.Drawing.Size(338, 212);
				            this.Controls.Add(this.button1);
				            this.Controls.Add(this.label1);
				            this.Controls.Add(this.radioButton2);
				            this.Controls.Add(this.radioButton1);
				            this.Name = "Form1";
				            this.Text = "日期与时间";
				            this.ResumeLayout(false);
				            this.PerformLayout();
				
						}
						#endregion
				
						/// 
						/// 应用程序的主入口点。
						/// 
						[STAThread]
						static void Main() 
						{
							Application.Run(new Form1());
						}
				
						private void button1_Click(object sender, System.EventArgs e)
						{
							if(radioButton1.Checked)
								label1.Text=DateTime.Now.Year+"年"
									+DateTime.Now.Month+"月"
									+DateTime.Now.Day+"日";
							if(radioButton2.Checked)
								label1.Text=DateTime.Now.Hour+"时"
									+DateTime.Now.Minute+"分"
									+DateTime.Now.Second+"秒";
						}
					}
				}
							

相关资源