form1.h
来自「Visual_C++.NET实用编程百例」· C头文件 代码 · 共 200 行
H
200 行
#pragma once
namespace login
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Form1 摘要
///
/// 警告: 如果您更改该类的名称,则需要更改
/// 与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。 否则,
/// 设计器将不能与此窗体关联的
/// 本地化资源正确交互。
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Label * label1;
private: System::Windows::Forms::Label * label2;
private: System::Windows::Forms::TextBox * textBox1;
private: System::Windows::Forms::TextBox * textBox2;
private: System::Windows::Forms::Button * button1;
private: System::Windows::Forms::Button * button2;
private: System::Windows::Forms::ErrorProvider * errorProvider1;
private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container * components;
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->label1 = new System::Windows::Forms::Label();
this->label2 = new System::Windows::Forms::Label();
this->textBox1 = new System::Windows::Forms::TextBox();
this->textBox2 = new System::Windows::Forms::TextBox();
this->button1 = new System::Windows::Forms::Button();
this->button2 = new System::Windows::Forms::Button();
this->errorProvider1 = new System::Windows::Forms::ErrorProvider();
this->SuspendLayout();
//
// label1
//
this->label1->Location = System::Drawing::Point(48, 24);
this->label1->Name = S"label1";
this->label1->Size = System::Drawing::Size(48, 23);
this->label1->TabIndex = 0;
this->label1->Text = S"用户名";
//
// label2
//
this->label2->Location = System::Drawing::Point(48, 64);
this->label2->Name = S"label2";
this->label2->Size = System::Drawing::Size(48, 23);
this->label2->TabIndex = 1;
this->label2->Text = S"密 码";
//
// textBox1
//
this->errorProvider1->SetError(this->textBox1, S"用户名不能为空");
this->textBox1->Location = System::Drawing::Point(104, 24);
this->textBox1->Name = S"textBox1";
this->textBox1->Size = System::Drawing::Size(120, 21);
this->textBox1->TabIndex = 2;
this->textBox1->Text = S"";
this->textBox1->Validating += new System::ComponentModel::CancelEventHandler(this, validating);
this->textBox1->Validated += new System::EventHandler(this, textBox1_Validated);
this->textBox1->Leave += new System::EventHandler(this, FocusLeave);
//
// textBox2
//
this->errorProvider1->SetError(this->textBox2, S"密密不能为空");
this->textBox2->Location = System::Drawing::Point(104, 64);
this->textBox2->Name = S"textBox2";
this->textBox2->PasswordChar = '*';
this->textBox2->Size = System::Drawing::Size(120, 21);
this->textBox2->TabIndex = 3;
this->textBox2->Text = S"";
this->textBox2->Validating += new System::ComponentModel::CancelEventHandler(this, validating);
this->textBox2->Validated += new System::EventHandler(this, textBox1_Validated);
//
// button1
//
this->button1->Location = System::Drawing::Point(56, 104);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(56, 23);
this->button1->TabIndex = 4;
this->button1->Text = S"登录";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(176, 104);
this->button2->Name = S"button2";
this->button2->Size = System::Drawing::Size(56, 23);
this->button2->TabIndex = 5;
this->button2->Text = S"退出";
this->button2->Click += new System::EventHandler(this, button2_Click);
//
// errorProvider1
//
this->errorProvider1->BlinkStyle = System::Windows::Forms::ErrorBlinkStyle::AlwaysBlink;
this->errorProvider1->ContainerControl = this;
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
this->ClientSize = System::Drawing::Size(288, 142);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
this->MinimizeBox = false;
this->Name = S"Form1";
this->ShowInTaskbar = false;
this->Text = S"登录";
this->Load += new System::EventHandler(this, Form1_Load);
this->ResumeLayout(false);
}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
if(textBox1->Text->Equals("name") && textBox2->Text->Equals("password"))
MessageBox::Show ("您好,欢迎您使用本系统","欢迎");
else
{
MessageBox::Show("您输入的用户名、密码错误","错误");
textBox1->Text = "";
textBox1->Text = "";
textBox1->Focus();
}
}
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{
this->Close();
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
//设置窗体的AcceptButton和CancelButton属性
//当用户按下回车键时,响应button1的事件
//当用户按下Esc键时,响应button2的事件
this->AcceptButton = button1;
this->CancelButton = button2;
textBox1->Focus ();
}
private: System::Void FocusLeave(System::Object * sender, System::EventArgs * e)
{
}
private: System::Void validating(System::Object * sender, System::ComponentModel::CancelEventArgs * e)
{
if(textBox1->Text =="")
errorProvider1->SetError(textBox1,"用户名不能为空");
}
private: System::Void textBox1_Validated(System::Object * sender, System::EventArgs * e)
{
if(textBox1->Text =="")
errorProvider1->SetError(textBox1,"用户名不能为空");
}
};
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?