簡體   English   中英

C#Windows窗體-文本框上的SendMessage EM_SETCUEBANNER不起作用

[英]C# Windows Forms - SendMessage EM_SETCUEBANNER on textbox not working

我正在使用Windows窗體的C#開發應用程序。 我想為我的文本框添加一個占位符,並從User32.dll找到了SendMessage的方法。 這是我的代碼(放置在LoginForm.cs中,如果設置文件不存在,這是第一種形式):

私有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);

被放置在類里面。 作為我的構造函數,我得到了:

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");
}

我的hostnameportusernamepassworddatabase都是文本框。 但是,如果我運行我的應用程序,則它不應用占位符,而只專注於最后一個文本框。

我究竟做錯了什么? 我沒有錯誤。

我很傻,我忘了添加Application.EnableVisualStyles(); 到我的Program.cs。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM