2、弹出窗体的设计
(1)窗体设计
(2)关键类代码设计
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace XXXXX
- {
- public partial class CheckPasswd : Form
- {
- public int SecFresh; // 一个公有成员,记录密码数值
- public CheckPasswd()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.maskedTextBox1.Text != "")
- {
- SecFresh = Convert.ToInt32(this.maskedTextBox1.Text.Trim());
- this.DialogResult = DialogResult.OK;
- }
- }
- catch { }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
(3)第三方调用时关键代码
- CheckPasswd frmset = new CheckPasswd();
- if (frmset.ShowDialog(this) == DialogResult.OK)
- {
- if (Convert.ToString(frmset.SecFresh) == "123456")
- {
- }
- else
- {
- MessageBox.Show("Password is incorrect.");
- return;
- }
- }
- else
- return;