zoukankan      html  css  js  c++  java
  • 简单的Windows登陆界面设计

    要求:
    1.用户名必须为字母。
     1 //限定用户名必须为字母
     2         private void txtName_KeyPress(object sender, KeyPressEventArgs e)
     3         {
     4             if ((e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z'))
     5             {
     6                 e.Handled = false;
     7             }
     8             else {
     9                 MessageBox.Show("用户名只能为字母!");
    10                 e.Handled = true;
    11             }
    12         }
    2.光标进入文本框时背景蓝色,文字白色;光标离开文本框时,背景白色,文字黑色。
    界面:
     1   //光标进入文本框时,背景为蓝色,字体为白色;
     2         //光标离开文本框时,背景为白色,字体为黑色。
     3         private void txtName_Enter(object sender, EventArgs e)
     4         {
     5             txtName.ForeColor = Color.White;
     6             txtName.BackColor = Color.Blue;
     7         }
     8 
     9         private void txtName_Leave(object sender, EventArgs e)
    10         {
    11             txtName.BackColor = Color.White;
    12             txtName.ForeColor = Color.Black;
    13         }

    3.当输入用户名“admin”和密码“123”之后,单击”确定“按钮,系统将弹出消息框以显示输入正确,否则显示用户名或密码错误的提示信息。

     1 private void btnLogin_Click(object sender, EventArgs e)
     2         {
     3             string userName = txtName.Text;
     4             string password = txtPwd.Text;
     5             if (userName == "admin" && password == "123")
     6             {
     7                 MessageBox.Show("欢迎进入个人理帐系统!", "登陆成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     8             }
     9             else
    10             {
    11                 MessageBox.Show("您输入的用户名或密码错误!", "登录失败!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    12             }
    13         }

    4.单击”取消“按钮,清除输入信息,并将光标定位在txtName文本框中。

    1   private void btnCancel_Click(object sender, EventArgs e)
    2         {
    3             txtName.Text = "";
    4             txtPwd.Text = "";
    5             txtName.Focus();
    6         }
    5.最终界面: 
     
    小技巧:为label设置Image属性,为了让图片完整显示出来,需要把label的AutoSize属性设置为false,然后适当拉大label大小。还要注意,ImageAlign属性设置为MiddleLeft,TextAlign属性设置为MiddleRight。
     

    Notice:

    (1)ico:是Windows图标文件格式的一种,可以存储单个图案、多尺寸、多色板的图标文件。
    (2)MessageBox:消息框,显示一个模态对话框,其中包含一个系统图标、 一组按钮和一个简短的特定于应用程序消息,如状态或错误的信息。
    (3)Button的快捷键通过设置Text属性为”取消(&C)“实现。
    (4)此练习使用的软件为Visual Studio 2012,图形资源由VS提供,据说在VS的安装文件夹Common7ImageLibrary中能找到,没有的话,可以到官网下载。

     

  • 相关阅读:
    爬取诗词名句网数据并做简单数据分析
    python3 协程Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x0918BAC0>
    scrapy框架中多个spider,tiems,pipelines的使用及运行方法
    python爬虫模拟登录的图片验证码处理和会话维持
    python使用selenium驱动chromium防止浏览器自动升级失效!
    爬虫篇-博客园搜索爬取
    复合索引,不走索引情况
    去掉Oracle连接超时限制
    C# 正则表达式
    Clean Code
  • 原文地址:https://www.cnblogs.com/wsw-tcsygrwfqd/p/4981117.html
Copyright © 2011-2022 走看看