简体   繁体   English

ContextMenuStrip中的TextBox离开事件未触发

[英]TextBox leave event in ContextMenuStrip not firing

I have a ContextMenuStrip containing two TextBoxes. 我有一个包含两个TextBoxes的ContextMenuStrip。

I want the validate the text inserted in a TextBox by using the TextBox.Leave event, but whenever I click outside the TextBox or the ContextMenuStrip, the event does not fire. 我想通过使用TextBox.Leave事件来验证插入到TextBox中的文本,但是每当我在TextBox或ContextMenuStrip之外单击时,该事件都不会触发。 The same for other events, like Validate, Enter etc. However, some events like MouseEnter or Click work. 对于其他事件,如Validate,Enter等,也是如此。但是,某些事件如MouseEnter或Click起作用。

Do you have any ideas? 你有什么想法?

Thank you! 谢谢!

Just create LostFocus event handler manually. 只需手动创建LostFocus事件处理程序。 NOTE- LostFocus event is not showing in VS designer. 注意LostFocus事件未在VS设计器中显示。

    public Form1()
    {
        InitializeComponent();

        toolStripTextBox1.LostFocus += ToolStripTextBox1_LostFocus;
    }
    private void ToolStripTextBox1_LostFocus(object sender, EventArgs e)
    {
        //Your code!!!
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM