向 MemoExEdit 控件添加字符计数器

发布于 2024-09-13 08:31:48 字数 531 浏览 4 评论 0原文

我正在尝试制作一个字符计数器,40/200...41/200等等。现在,对于文本框控件,我用类似的东西挂钩到 KeyUp 事件...

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

不幸的是,MemoExEdit 控件有一个弹出窗口,您可以在其中键入文本,并且似乎被隐藏。我尝试了KeyUpEditValueChangingTextChanged,它们都做了同样的事情。在用户关闭弹出窗口之前它们不会触发。我猜测它是一个复合控件,在关闭时传输编辑值。

关于如何参加弹出窗口活动有什么想法吗?有其他方法可以做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最单纯的乌龟 2024-09-20 08:31:48

只是因为我在其他地方找不到这个,所以我会为了其他人的利益发布我的解决方案。

订阅 MemoExEdit 控件的 Popup 事件,然后在其中订阅 EditValueChanging 事件。这就是你可以加入的地方。请参阅下面的我的工作版本。您自己可能需要进行调整。此外,弹出事件是在我的 Designer.cs 文件中创建的。

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文