- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的用户正在组合框中输入密码,因此我想显示 *
来代替用户键入的内容。到目前为止没有问题。下面显示的例程完美运行。但是,我还想让用户选择显示密码。当我使用 SetPasswordChar=false 调用下面的例程时,它会发送参数为零的 EM_SETTPASSWORDCHAR。我希望组合框显示用户输入的文本。但它仍然显示*
。知道我缺少什么吗?
//==============================================================================
// SetComboBoxPasswordChar
//------------------------------------------------------------------------------
// Set the Password Char for a tComboBox.
//
// This is done using by sending an EM_SETPASSWORDCHAR message to the edit box
// sub-control of the combo box.
//
//http://msdn.microsoft.com/en-us/library/windows/desktop/bb761653(v=vs.85).aspx
//
// wParam - The character to be displayed in place of the characters typed by
// the user. If this parameter is zero, the control removes the current password
// character and displays the characters typed by the user.
//==============================================================================
procedure SetComboBoxPasswordChar
( const nComboBox : tComboBox;
const nSetPasswordChar : boolean );
var
C : integer;
H : tHandle;
begin
// Get handle of the combo box
H := nComboBox . Handle;
// Get handle of the edit-box portion of the combo box
H := GetWindow ( H, GW_CHILD );
// If nSetPasswordChar is true,
// set password char to asterisk
// Otherwise, clear the password char
if nSetPasswordChar then
C := ord('*')
else
C := 0;
SendMessage ( H, EM_SETPASSWORDCHAR, C, 0 );
end;
最佳答案
我怀疑(并且刚刚通过 XE2 中的快速测试应用程序确认)这是因为您只是假设编辑控件的 HWND
是 GetWindow(H, GW_CHILD) 返回的内容;
,我认为这不是一个安全的假设。 :-) COMBOBOX
控件实际上由三个 HWND
值组成:一个用于整个控件,一个用于编辑部分,一个用于下拉列表。
获取所需句柄的更正确方法是使用 GetComboBoxInfo并使用 COMBOBOXINFO 的 hwndItem
成员结构:
var
CBI: TComboBoxInfo;
begin
// ..... Other code
CBI.cbSize := SizeOf(CBI);
H := nComboBox.Handle;
if GetComboBoxInfo(H, CBI) then
SendMessage(cbi.hwndItem, EM_SETPASSWORDCHAR, C, 0);
end;
为了快速、简单地说明其工作原理,请将 TComboBox
放在新的空白表单上,为 ComboBox1.OnDblClick
事件处理程序添加一个事件处理程序,然后添加将以下代码添加到您的表单中:
const
PasswordChars: array[Boolean] of Integer = (0, Ord('*'));
var
Ch: Integer = 0;
UsePWdChar: Boolean = False;
procedure TForm1.ComboBox1DblClick(Sender: TObject);
var
Ch: Integer;
CBI: TComboBoxInfo;
begin
CBI.cbSize := SizeOf(CBI);
UsePwdChar := not UsePwdChar;
Ch := PasswordChars[UsePwdChar];
if GetComboBoxInfo(ComboBox1.Handle, CBI) then
SendMessage(cbi.hwndItem, EM_SETPASSWORDCHAR, Ch, 0)
end;
这使用 ComboBox
编辑控件中的默认 ComboBox1
值,并在密码字符 *
之间来回切换并且每次双击组合框时都没有。
关于delphi - 重置 tComboBox 的 PasswordChar 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11207117/
我想在用户单击按钮时将文本框中的 PasswordChar 设为空(这样他们就可以确认自己写得正确,这比输入两次要容易得多) 但是,当我这样做时: password.PasswordChar = nu
我正在使用 vs2015 编写一个 c# 程序,但是在 PasswordChar 的文本框的属性字段中没有选项。我试图做到这一点,以便文本框显示“*”而不是输入的文本。 我已尝试在 mytxtbox.
这个问题在这里已经有了答案: Null Password Char in Winform [duplicate] (4 个答案) 关闭 9 年前。 我有一个带有 PasswordChar 的文本框。
我的用户正在组合框中输入密码,因此我想显示 * 来代替用户键入的内容。到目前为止没有问题。下面显示的例程完美运行。但是,我还想让用户选择显示密码。当我使用 SetPasswordChar=false
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Which passwordchar shows a black dot (•) in a winforms
这里有一个简短的问题: 在 .Net 4.0 Winforms 中,如何使用 Textbox 的 PasswordChar 属性来显示常见的黑点 作为一个角色?是否有一些我可以使用的字体将其作为字符?
我有一个密码文本框,我想为密码设置字符,那么在asp.net中可以使用哪个属性? 最佳答案 PasswordChar 属性在此命名空间 System.Windows.Forms 下。它不适用于 as
我的表单上有 2 个控件:TCheckBox 和 TEdit。 我想使用实时绑定(bind)来执行此操作: 当 TCheckBox.Checked = True 时,设置 TEdit.Password
我是一名优秀的程序员,十分优秀!