Add character counter to MemoExEdit control

蹲街弑〆低调 提交于 2019-12-11 04:17:20

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/3424171/add-character-counter-to-memoexedit-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!