如何记住登录表单的用户名或密码 [英] How to Remember username or password for login form

查看:359
本文介绍了如何记住登录表单的用户名或密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在C#Windows窗体应用程序中创建了一个示例登录表单,我想要在我的登录表单中添加记住用户名"或密码"功能.

I have created a sample Login form in C# Windows Form Application and what I want is to add Remember username or password feature to my login form.

我只需要提供我的用户名,因为它会记住我的密码并自动填写密码字段(例如,像gmail auth中一样).

I just need to provide my username, cause it will remember my password and automatically fill in the password field (Ex. Like in gmail auth).

我该如何实现?

这是我的登录表单应用程序:- http://i50.tinypic.com/2pzxjb7.jpg

This is my Login form app:- http://i50.tinypic.com/2pzxjb7.jpg

推荐答案

我将使用可以定义具有可定制的范围的多个强类型设置;用户或应用程序.有一个在Visual Studio中为它的接口.如果打开项目属性,则可以选择设置选项卡.如果您的项目中没有设置文件,则可以单击此处的链接使Visual Studio创建一个.一旦你有一个,你可以在名称,类型,范围和默认的应用程序设置值输入.

You can define multiple strongly typed settings with customizable scope; user or application. There is an interface for it in Visual Studio. If you open the project properties, you can select the settings tab. If you don't have a settings file in your project, you can click the link here to have Visual Studio create one. Once you have one, you can enter in the names, types, scope, and default values of your application settings.

完成所有这些设置后,在<ProjectName>.Properties命名空间下将有一个名为Settings的类.然后,您可以使用Settings.Default静态属性访问默认设置,更改其值,然后调用Save方法以保留它们.

After you set all this up, you will have a class called Settings under the <ProjectName>.Properties namespace. You can then use the Settings.Default static property to access the default settings, change their values, and call the Save method to persist them.

启动应用程序时,将保存持久设置,您可以通过编程方式将其输入到用户界面中.

When you start your app up, the persisted settings are loaded and you could programmatically enter them into your user interface.

如果这一切对于您的情况来说都是致命的,那么您只需手动在相对于用户个人资料文件夹的定义位置中的文件中进行读写操作即可.

If all of this is over-kill for your scenario, you could just manually read/write to/from a file in a defined location relative to the user's profile folder.

这篇关于如何记住登录表单的用户名或密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆