⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Csharp实例编程百例.rar
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace LoginApp
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label1;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// checkBox1
			// 
			this.checkBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.checkBox1.Location = new System.Drawing.Point(56, 121);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(168, 56);
			this.checkBox1.TabIndex = 0;
			this.checkBox1.Text = "启动自动登录";
			this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(160, 57);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(48, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "10";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 61);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(136, 24);
			this.label1.TabIndex = 2;
			this.label1.Text = "等待空闲时间(秒):";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(312, 229);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label1,
																		  this.textBox1,
																		  this.checkBox1});
			this.Name = "Form1";
			this.Text = "AutoLoginApp";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());			
		}

		public string strUserName
		{//只读属性:用户名
			get
			{
				return("guest");
			}
		}
		public string strPassWord
		{//只读属性:密码
			get
			{
				return("guest");
			}
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			Form2 frmLogin = new Form2();
			frmLogin.ShowDialog(this);	//主窗体作为模式对话框的拥有者
		}

		private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
		{
			if (checkBox1.Checked )		//添加事件处理函数与事件的关联
			{	
				Application.Idle += new System.EventHandler(this.OnIdle );
			}
			else						//撤销事件处理函数与事件的关联
			{
				Application.Idle -= new System.EventHandler(this.OnIdle );
			}
		}

		private void OnIdle(object sender, System.EventArgs e)
		{	//如果应用程序空闲,启动timer
			timer1.Interval = Int32.Parse (textBox1.Text) *1000;
			timer1.Start ();
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{	//时间到,停止timer,询问是否再次登录
			timer1.Stop ();
			if (MessageBox.Show ("是否再次登录?","提示",MessageBoxButtons.YesNo ,MessageBoxIcon.Question )== DialogResult.Yes  )
			{
				Application.Idle -= new System.EventHandler(this.OnIdle );
				Form2 frmLogin = new Form2();	//打开登录对话框
				frmLogin.ShowDialog(this);	
				Application.Idle += new System.EventHandler(this.OnIdle );
			}
			else	//不再登录,退出程序
			{
				Application.Exit ();
			}
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -