C#TextBox设置提示文本
效果展示
核心代码
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- private static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
- public static void SetHintText(Control control, string text)
- {
- SendMessage(control.Handle, 0x1501, 0, text);
- }
- public FrmUpdataPassword()
- {
- InitializeComponent();
- SetHintText(txt_OldPassword, "初始密码为:123456");
- SetHintText(txt_NewPassword, $"6-{txt_NewPassword.MaxLength}位数字或字母");
- btn_Enter.Focus();
- }
- //显示/隐藏密码
- private void chb_ShowPassword_CheckedChanged(object sender, EventArgs e)
- {
- //txt_OldPassword.UseSystemPasswordChar = !chb_ShowPassword.Checked;
- txt_NewPassword.UseSystemPasswordChar = !chb_ShowPassword.Checked;
复制代码 总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持晓枫资讯。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |