添加字符计数器MemoExEdit控制计数器、字符、MemoExEdit

2023-09-07 09:37:29 作者:久溺玻璃岛

我想使字符计数器,200分之40...二百分之四十一的等。现在,一个文本框控件,我挂钩到keyup事件有这样的事情...

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

不幸的是,MemoExEdit控制有一个弹出式窗口键入的文本,而似乎的隐藏。我试过的KeyUp EditValueChanging 框TextChanged ,和他们都做同样的事情。他们不火,直到用户关闭弹出窗口。我猜测,这是一个复合控件传送的EditValue它关闭时。

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.

订阅MemoExEdit控制的弹出式菜单事件,然后把里面的订阅EditValueChanging事件。这就是你可以在钩。下面为我的工作版本。调整可能需要为你自己。此外,弹出事件在我的Designer.cs文件中创建。

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