0
votes

I have Windows 7 with 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).

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().

enabledTextboxes, Textbox1.focus()

when the user doesn't enter any value and hits the radiobutton1 the two textboxes are set to enabled = false again.

When you do that, the disabled textbox1 looks different (inset) to textbox2 because it had the focus before it was disabled.

disabledTextbox1 looks different

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. When you now hit radiobutton1 both disabled text boxes are looking the same.

What event can I use to take away the focus of the text box (which has the focus) before I hit the radiobutton1?

1
Hello and Welcome to Stack Overflow! As you have noticed this is just a redrawing glitch that happens when you disable a focused textbox and it shouldn't be anything to worry about. However if you want to get rid of it, try giving focus to another control by calling the Control.Focus() method before disabling your textbox. If that doesn't work also try calling Refresh() on your textbox to force it to redraw itself before disabling.Visual Vincent

1 Answers

1
votes

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.

For radiobutton1 i created a mouseenter and a mouseleave event. when the mouse is over radiobutton1 the "hidden" label gets the focus. when the mouse leaves radiobutton1 the textbox1 gets the focus again.

the refresh() method didn't help.

Thx for your comment Visual Vincent!

p.s.: i don't know why but only setting the focus to the label without using the mouse events didn't solve the problem!