I'm making an application in C# with windows forms. I want to have a placeholder for my textboxes and I found the method of SendMessage from User32.dll. Here's my code (placed in LoginForm.cs which is one of the first forms if settings file doesn't exist):
private const int EM_SETCUEBANNER = 0x1501;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SendMessage(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)]string lParam);
Is placed inside the class. As my constructor I got:
public LoginForm()
{
InitializeComponent();
SendMessage(hostname.Handle, EM_SETCUEBANNER, 0, "Hostname");
SendMessage(port.Handle, EM_SETCUEBANNER, 0, "Port");
SendMessage(username.Handle, EM_SETCUEBANNER, 0, "Username");
SendMessage(password.Handle, EM_SETCUEBANNER, 0, "Password");
SendMessage(database.Handle, EM_SETCUEBANNER, 0, "Database");
}
My hostname
, port
, username
, password
, database
are all textboxes. But if I run my application, it doesn't apply the placeholders, it simply focuses on the last textbox.
What am I doing wrong? I get no errors.
I was dumb, I forgot to add Application.EnableVisualStyles();
to my Program.cs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.