是否可以指示 DataGridView 单元格用星号屏蔽输入的字符?

发布于 2024-10-10 08:52:47 字数 80 浏览 0 评论 0原文

有没有办法在输入时将 DataGridView 单元格中输入的字符替换为星号?如果是这样,我该怎么做?任何帮助表示赞赏。

Is there a way to replace the characters entered in a cell of a DataGridView with an asterisk while entering them? If so, how can I do this? Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉宸 2024-10-17 08:52:47

正如 Mark Rideout 在中所写的那样在 Social.msdn.microsoft.com 上找到的答案

处理 EditingControlShowing 事件
然后将编辑控件投射到
文本框并手动设置
UseSystemPasswordChar 设置为 true:

TextBox t = e.Control as TextBox;
if (t != null)
{
    t.UseSystemPasswordChar = true;
}

As Mark Rideout writes in his answer found on social.msdn.microsoft.com

Handle the EditingControlShowing event
and then cast the editing control to a
TextBox and manually set the
UseSystemPasswordChar to true:

TextBox t = e.Control as TextBox;
if (t != null)
{
    t.UseSystemPasswordChar = true;
}
墟烟 2024-10-17 08:52:47

尝试这个

在 DataGridView EditingControlShowing 事件

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control.GetType() == typeof(DataGridViewTextBoxEditingControl))
            {
                TextBox txt = (TextBox)e.Control;
                txt.PasswordChar = '*';
            }
        }

和单元格格式化事件中

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if(e.Value != null)
                e.Value = new String('*', e.Value.ToString().Length);
        }

希望这有帮助

try this

in the DataGridView EditingControlShowing event

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (e.Control.GetType() == typeof(DataGridViewTextBoxEditingControl))
            {
                TextBox txt = (TextBox)e.Control;
                txt.PasswordChar = '*';
            }
        }

and in the Cell Formating Event

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if(e.Value != null)
                e.Value = new String('*', e.Value.ToString().Length);
        }

hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文