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;
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论