开发者

Add character counter to MemoExEdit control

开发者 https://www.devze.com 2023-01-10 18:01 出处:网络
I am trying to make a character counter, 40/200...41/200 and so on.Now for a textbox control I am hooking into the KeyUp Event with something like this...

I am trying to make a character counter, 40/200...41/200 and so on. Now for a textbox control I am hooking into the KeyUp Event with something like this...

    public static void GetRemainingChars(MyTextBox txt, LabelControl lbl)
    {
        var maxChars = txt.Properties.MaxLength;
        lbl.Text = txt.Text.Length + "/" + maxChars;
    }

Unfortunately the MemoExEdit control has a popup window you type the text into and that seems to be hidden. I tried the KeyUp, EditValueChanging, TextChanged, and they all do the same thing.开发者_开发百科 They don't fire till the user closes the popup. I am guessing that it is a composite control that transfers the editvalue when it closes.

Any ideas on how I can get at the popups events? Is there a different way to do this?


Just because I couldn't find this anywhere else I will post my solution for other's benefit.

Subscribe to the Popup Event of the MemoExEdit control, then inside that subscribe to the EditValueChanging Event. That is where you can hook in. See below for MY working version. Tweaks may be needed for yourself. Also, the Popup Event is created in my Designer.cs file.

private void memContactWith_Properties_Popup(object sender, EventArgs e)
{
   MemoExPopupForm popupForm = (sender as DevExpress.Utils.Win.IPopupControl).PopupWindow as MemoExPopupForm;
   MemoEdit me = popupForm.Controls[2] as MemoEdit;
   me.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(me_EditValueChanging);            
}

void me_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
   var memo = (sender as MemoEdit);
   var maxChars = memo.Properties.MaxLength;
   lblContactWithCharCount.Text = memo.Text.Length + "/" + maxChars;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消