简体   繁体   English

禁用文本框的问题,该文本框在被禁用之前已具有焦点

[英]Problem with Disabled Textbox which had focus before it was disabled

I have Windows 7 with Visual Studio 2017 (Visual Basic). 我有Windows 7和Visual Studio 2017(Visual Basic)。

I have a group box with two radio buttons and two text boxes. 我有一个带有两个单选按钮和两个文本框的组框。 When radiobutton1 is checked the two text boxes are not available ( Textbox.Enabled = false ). 选中radiobutton1 ,两个文本框不可用( Textbox.Enabled = false )。

disabledTextboxes

When the user hits radiobutton2 the two text boxes are set to enabled = true and the first text box gets the focus with textbox1.focus() . 当用户单击radiobutton2 ,两个文本框设置为enabled = true ,第一个文本框通过textbox1.focus()获得焦点。

enabledTextboxes,Textbox1.focus()

when the user doesn't enter any value and hits the radiobutton1 the two textboxes are set to enabled = false again. 当用户未输入任何值并单击单选按钮1时,两个文本框将再次设置为enabled = false。

When you do that, the disabled textbox1 looks different (inset) to textbox2 because it had the focus before it was disabled. 当你这样做,残疾人textbox1看起来不同(插图)到textbox2 ,因为它有焦点之前它被禁用。

disabledTextbox1看起来不同

When radiobutton2 is checked and you fill in, for example, numvalues to the text boxes and you use the enter button to validate both text boxes, there is no focus on the text boxes anymore. radiobutton2被选中,你填写,例如, numvalues到文本框,并使用回车键来验证这两个文本框,没有专注于文本框了。 When you now hit radiobutton1 both disabled text boxes are looking the same. 现在单击radiobutton1两个禁用的文本框看起来都一样。

What event can I use to take away the focus of the text box (which has the focus) before I hit the radiobutton1 ? 在单击radiobutton1之前,我可以使用什么事件来消除文本框(具有焦点)的焦点?

the problem is solved. 问题已经解决了。

because i had no other control to give the focus to i created a label with the width of 0 so one can't see the IBeam cursor. 因为我没有其他控件可以将焦点移至我创建的标签宽度为0,所以看不到IBeam光标。

For radiobutton1 i created a mouseenter and a mouseleave event. 我为单选按钮1创建了mouseenter事件和mouseleave事件。 when the mouse is over radiobutton1 the "hidden" label gets the focus. 当鼠标悬停在单选按钮1上时,“隐藏”标签将获得焦点。 when the mouse leaves radiobutton1 the textbox1 gets the focus again. 当鼠标离开radiobutton1时,textbox1再次获得焦点。

the refresh() method didn't help. refresh()方法没有帮助。

Thx for your comment Visual Vincent! 感谢您的评论Visual Vincent!

ps: i don't know why but only setting the focus to the label without using the mouse events didn't solve the problem! ps:我不知道为什么,但是仅将焦点设置到标签而不使用鼠标事件并不能解决问题!

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

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