WPF C#中的鼠标离开控件 [英] mouse leave control in WPF C#

查看:72
本文介绍了WPF C#中的鼠标离开控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生,

我正在使用两个文本框,当我用鼠标离开第一个文本框时(通过在窗体上的另一个文本框上滑动),它出来了.

我的要求:如果文本框为空,则光标不会出来.请帮助我
谢谢

Dear sir,

I am using two textbox, When I leave the first textbox using with the mouse (by clilcking on another textbox on the form) it is come out.

my quoestion: if the textbox is empty the cursor not come out. please help me
Thanks

推荐答案

我假设您的意思是问文本是否为空时如何将焦点设置回textBox1.为此,您需要处理PreviewLostKeyboardFocus事件.在那里,您检查文本框是否为空,是否将e.handled设置为true,如下所示:-

I assume you mean to ask how to set the focus back to textBox1 if the text is empty. To do this you need to handle the PreviewLostKeyboardFocus event. There you check if textbox is empty and if so set e.handled to true like this:-

<TextBox Name="textBox1" PreviewLostKeyboardFocus="textBox1_PreviewLostKeyboardFocus" />







private void textBox1_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        {
            if (textBox1.Text == string.Empty)
            {
                e.Handled = true;
            }
        }



希望对您有帮助



Hope this helps


这篇关于WPF C#中的鼠标离开控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆