views:

29

answers:

1

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?

+2  A: 

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;
}
Refracted Paladin
I can only confirm that your code is absolutely correct :)
DevExpress Team