Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12402573
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类:

2012-07-16 14:11:56

一、功能需求:
某个弹出的窗体可以输入密码,且居屏幕中间。

二、解决方案:
1、解决弹出窗体居中的问题
  Form 有个方便的属性,StartPoint可以用来设置Form的特殊位置。
  比如说,屏幕的正中,你可以设为CenterScreen。
 

image

 

 

image

 

2、弹出窗体的设计

(1)窗体设计

 

image


(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;

阅读(5542) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~