c# - EM_SETCUEBANNER doesn't works on RichTextBox -
i've been using em_setcuebanner
implement place-holder on textbox
es, working fine until used on richtextbox
. doesn't display text.
here's code:
[dllimport("user32.dll", charset = charset.auto, setlasterror=true)] public static extern int32 sendmessage(intptr hwnd, int msg, int wparam, [marshalas(unmanagedtype.lpwstr)]string lparam); bool setplaceholder(textboxbase control, string text) { const int em_setcuebanner = 0x1501; return natives.sendmessage(control.handle, em_setcuebanner, 0, text) == 1; }
using on rtb returns false
marshal.getlastwin32error()
has value of 0
.
i can't find specific rtb on edit control messages
.
how can fix this?
this should not surprise much, beyond the documentation, multi-line textbox doesn't support cue.
nothing can't fix, isn't hard do. add new class project , paste code shown below. compile. drop new control top of toolbox onto form, replacing existing one.
using system; using system.drawing; using system.windows.forms; class richtextboxex : richtextbox { public string cue { { return cue; } set { showcue(false); cue = value; if (this.focused) showcue(true); } } private string cue; protected override void onenter(eventargs e) { showcue(false); base.onenter(e); } protected override void onleave(eventargs e) { showcue(true); base.onleave(e); } protected override void onvisiblechanged(eventargs e) { if (!this.focused) showcue(true); base.onvisiblechanged(e); } private void showcue(bool visible) { if (this.designmode) visible = false; if (visible) { if (this.text.length == 0) { this.text = cue; this.selectall(); this.selectioncolor = color.fromargb(87, 87, 87); } } else { if (this.text == cue) { this.text = ""; this.selectioncolor = this.forecolor; } } } }
Comments
Post a Comment