且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#弹出式窗口设计及窗体居屏幕中间

更新时间:2022-08-19 10:46:32















C#弹出式窗口设计及窗体居屏幕中间

 

 

C#弹出式窗口设计及窗体居屏幕中间

 

2、弹出窗体的设计

(1)窗体设计

 

C#弹出式窗口设计及窗体居屏幕中间


(2)关键类代码设计


  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;

  9. namespace XXXXX
  10. {
  11.     public partial class CheckPasswd : Form
  12.     {
  13.         public int SecFresh; // 一个公有成员,记录密码数值

  14.         public CheckPasswd()
  15.         {
  16.             InitializeComponent();
  17.         }

  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             try
  21.             {
  22.                 if (this.maskedTextBox1.Text != "")
  23.                 {
  24.                     SecFresh = Convert.ToInt32(this.maskedTextBox1.Text.Trim());
  25.                     this.DialogResult = DialogResult.OK;
  26.                 }
  27.             }
  28.             catch { }
  29.         }

  30.         private void button2_Click(object sender, EventArgs e)
  31.         {
  32.             this.Close();
  33.         }
  34.     }
  35. }


(3)第三方调用时关键代码


  1. CheckPasswd frmset = new CheckPasswd();
  2. if (frmset.ShowDialog(this) == DialogResult.OK)
  3. {
  4.     if (Convert.ToString(frmset.SecFresh) == "123456")
  5.     {

  6.     }
  7.     else
  8.     {
  9.         MessageBox.Show("Password is incorrect.");
  10.         return;
  11.     }
  12. }
  13. else
  14.     return;