简体   繁体   English

如何在Windows应用程序C#应用程序中放置密码掩码

[英]How to put password mask in windows application c# Application

I am developing windows application to ask user to enter password in pop up box on that i am not able to put password mask, 我正在开发Windows应用程序,要求用户在弹出框上输入密码,因为我无法放置密码掩码,

if any on know could you please help me out this i am new to visual studio 如果有什么可以请您帮帮我,我是Visual Studio的新手

string pin=Microsoft.VisualBasic.Interaction.InputBox("Input User Pin Number", "Pin Number", "" );

在此处输入图片说明

There is no easy way of doing this with an InputBox. 使用InputBox没有简单的方法。 (You'd have to install a hook before showing the dialog, and then when it was displayed, hunt around for its textbox control and change its styles.) Better to just say "can't". (您必须在显示对话框之前安装一个钩子,然后在显示该对话框时,寻找它的文本框控件并更改其样式。)最好只说“不能”。 The InputBox wasn't designed to be customizable. InputBox并非设计为可定制的。 In fact, it wasn't even designed to be used by .NET applications. 实际上,它甚至没有被设计为供.NET应用程序使用。 It's an old classic VB thing, provided in the compatibility namespace merely to facilitate porting classic VB apps to VB.NET. 这是一个古老的经典VB东西,在兼容性名称空间中提供它只是为了方便将经典VB应用程序移植到VB.NET。

There is no real advantage in using it. 使用它没有真正的优势。 Just create your own form with a label, maybe an icon, and a textbox. 只需使用标签,图标和文本框创建自己的表单即可。 Set the textbox control's UseSystemPasswordChar property to true. 将文本框控件的UseSystemPasswordChar属性设置为true。 (You could do as rashfmnb suggested and set the PasswordChar property, but it is better to use the system's password character instead of your own, that way it always matches the user's expectations.) (您可以按照rashfmnb的建议进行操作并设置PasswordChar属性,但是最好使用系统的密码字符而不是您自己的密码字符,这样它始终可以满足用户的期望。)

Be sure to display your new form with the ShowDialog method so that it will be a modal dialog (blocking call), just like InputBox. 确保使用ShowDialog方法显示新表单,以便它将像输入框一样成为模式对话框(阻止调用)。

文本框的用户PasswordChar属性

You can't mask the chars in an InputBox. 您不能掩盖InputBox中的字符。

If you look at Interaction.InputBox Method on MSDN , there is no way to set it to be password input. 如果查看MSDN上的Interaction.InputBox方法 ,则无法将其设置为密码输入。

You will need to create a new Form, add your own Label and a TextBox, then set the PasswordChar property in the TextBox 您将需要创建一个新窗体,添加您自己的Label和一个TextBox,然后在TextBox中设置PasswordChar属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM