using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; namespace Remember
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//登录
private void btn_Login_Click(object sender, EventArgs e)
{
//记住密码
if (cb_remember.Checked == true)
{
WriteIni("My Section", this.tb_UserName.Text.ToString(), this.tb_Password.Text.ToString(),
string.Format(@"{0}\xtflz.dll", Application.StartupPath));
MessageBox.Show("写入成功");
}
else
{
WriteIni("My Section", this.tb_UserName.Text.ToString(),"",
string.Format(@"{0}\xtflz.dll", Application.StartupPath));
}
}
#region 登录记住密码
/// <summary>
/// 提供INI文件的写操作(如Key和Value都为空(null), 则删除Section指定的节下所有键值(包括节名)[如Value为空(null), 则删除Section节下Key键值])
/// </summary>
/// <param name="Section">指定的节名</param>
/// <param name="Key">指定的键名</param>
/// <param name="Value">Key的值(请将相应的类型ing,long...转换为string类型)</param>
/// <param name="FilePath">INI文件全路径</param>
/// <returns></returns>
public static bool WriteIni(string Section, string Key, string Value, string FilePath)
{
//成功返回非零
long lRe = WritePrivateProfileString(Section, Key, Value, FilePath);
return lRe == 0L ? false : true;
}
/// <summary>
/// 提供INI文件的读操作
/// </summary>
/// <param name="Section">指定的节名</param>
/// <param name="Key">指定的键名</param>
/// <param name="FilePath">INI文件全路径</param>
/// <returns>请将string类型转换为相应int,long的类型(返回值不应超过255字符)</returns>
public static string ReadIni(string Section, string Key, string FilePath)
{
int Size = ;
StringBuilder ReStr = new StringBuilder();
GetPrivateProfileString(Section, Key, "ERROR...", ReStr, Size, FilePath);
if (ReStr.ToString() == "ERROR...")
{
return null;
}
return ReStr.ToString();
}
/// <summary>
/// C#申明INI文件的写操作函数WritePrivateProfileString()
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
/// <param name="FilePath"></param>
/// <returns></returns>
//读写INI文件功能
[System.Runtime.InteropServices.DllImport("kernel32")]
public static extern long WritePrivateProfileString(string Section,
//指定的节名
string Key,
//指定的键名
string Value,
string FilePath);
/// <summary>
/// C#申明INI文件的读操作函数GetPrivateProfileString
/// </summary>
/// <param name="Section"></param>
/// <param name="key"></param>
/// <param name="Def"></param>
/// <param name="RetVal"></param>
/// <param name="Size"></param>
/// <param name="FilePath"></param>
/// <returns></returns>
[System.Runtime.InteropServices.DllImport("kernel32")]
public static extern int GetPrivateProfileString(string Section,
//指定的节名
string key,
//指定的键名
string Def,
//如果未取得正确的值则返回自定义的字符串
StringBuilder RetVal,
//保存字符串值
int Size,
//指定RetVal的长度
string FilePath);
//ini文件路径(如果ini文件不在操作系统文件夹内,则必须指定ini文件的绝对路径)
#endregion 登录记住密码
private void tb_UserName_TextChanged(object sender, EventArgs e)
{
string s = this.tb_UserName.Text.ToString();
string result = ReadIni("My Section",s,string.Format(@"{0}\xtflz.dll",Application.StartupPath));
if (result == null || result == "")
{
this.tb_Password.Text = "";
this.cb_remember.Checked = false;
}
else
{
this.tb_Password.Text = result;
this.cb_remember.Checked = true;
}
}
}
}


C# winform 记住密码实现代码的更多相关文章

  1. winform 记住密码功能

      //登录        private void btn_Login_Click(object sender, EventArgs e)        {            //记住密码    ...

  2. WinForm——记住密码

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runti ...

  3. js中利用cookie实现记住密码功能

    在登录界面添加记住密码功能,代码如下: //设置cookie var passKey = '4c05c54d952b11e691d76c0b843ea7f9'; function setCookie( ...

  4. jquery.cookie.js 操作cookie实现记住密码功能的实现代码

    jquery.cookie.js操作cookie实现记住密码功能,很简单很强大,喜欢的朋友可以参考下.   复制代码代码如下: //初始化页面时验证是否记住了密码 $(document).ready( ...

  5. Cookie实现记住密码代码

    jsp页面 <%-- Created by IntelliJ IDEA. User: 60590 Date: 2019/11/28 Time: 14:10 To change this temp ...

  6. WinForm应用程序的开机自启、记住密码,自动登录的实现

    一.思路: 1.开机自启,自然是需要用到注册表,我们需要把程序添加到电脑的注册表中去 2.记住密码,自动登录,开机自启,在页面的呈现我们都使用复选框按钮来呈现 3.数据持久化,不能是数据库,可以是sq ...

  7. java实现记住密码功能(利用cookie)

    <br> <input type="text" id="userName" name="userName" value=& ...

  8. cookie实现记住密码

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  9. MiniTwitter记住密码等功能实现

    一.SharedPreferences的用法:(相关实现功能的只是了解) 由于SharedPreferences是一个接口,而且在这个接口里没有提供写入数据和读取数据的能力.但它是通过其Editor接 ...

随机推荐

  1. SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别

    SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层. SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,M ...

  2. 清空表中数据 id从1开始

    删除表的记录以后,如何使新记录的编号仍然从1开始有两种方法: 方法1: truncate table 你的表名 --这样不但将数据删除,而且可以重新置位identity属性的字段. 方法2: dele ...

  3. Combobox实现多项选择 Silverlight下“Combobox”怎样实现多项选择?

    把 combobox里面的项换成checkedbox 示例: combobox cbb=new combobox(); ) { CheckBox cb = new CheckBox(); cb.Com ...

  4. 编译安装bluez5.44

    1.下载 2. configure 提示需要glib 3.yum install glib 4.还是提示glib 5.yum install glib-devel 下载编译glib make inst ...

  5. 1.spring环境的搭建

    1.app.config <?xml version="1.0" encoding="utf-8" ?><configuration> ...

  6. 使用RSA进行信息加密解密的WebService示例

    使用RSA进行信息加密解密的WebService示例 按:以下文字涉及RSA对WebService传递的数据的加密解密,如果您已经熟知RSA或是有其它更好的方法请不要往下看以免浪费时间. WebSer ...

  7. 2018.10.14 loj#516. DP 一般看规律(启发式合并)

    传送门 注意到一种颜色改了之后就不能改回去了. 因此可以启发式合并. 每次把小的合并给大的. 这样每个数最多被合并logloglog次. 如果维护一棵比较下标的平衡树的话,对于答案有贡献的就是每个数与 ...

  8. 被弃用的php函数以及被那个代替

      原文链接 http://blog.csdn.net/a11085013/article/details/8937848   下面列举了部分被弃用的函数:      call_user_method ...

  9. k8s的port、targetport、nodeport之间的区别

    先看举例: k8s集群中跑着一个tomcat服务,tomcat容器expose的端口为8080 apiVersion: v1 kind: Service metadata: name: tomcat- ...

  10. python3.4用循环往mysql5.7中写数据并输出

    #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...