首页 技术 正文
技术 2022年11月15日
0 收藏 516 点赞 2,852 浏览 2887 个字
 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 记住密码实现代码


    					
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901