-1

I have a winform with a toolstriptextbox where users can write some stuff. The problem is that the textbox does not release the focus using the following code:

this.ActiveControl = otherControl; 
OR
otherControl.Focus();

It is very strange because I can still see the text cursor blinking in the toolstriptextbox (if I press some other key it will appear in it).

Does any one know how to remove the cursor of toolstriptextbox?

PD. The toolstriptextbox is the only textbox inside the form.

Regarding to the comments...

In fact there are not several controls in the form. Some buttons in the toolstrip, a splitterPanel and a couple of picture boxes. I tried to focus the picture boxes and the toolstrip but sometimes the form loses its handlers of events and the only way to solve this is to open or to focus any other app and go back(this restores the handlers). So far the only way to avoid that is to focus the splitterPanel. I do understand that theoretically the splitterPanel is not focusable, but that is the only workaround I have found.

Finaly when the splitterPanel is focused the initial behaviour occurs.

Thanks for your comments.

Ayorus
  • 477
  • 7
  • 16
  • 1
    What is the "otherControl" you are trying to focus on? And where are you calling that code? – LarsTech Aug 03 '16 at 21:44
  • What's the context that you are trying to do that and what's the type of other control which you are trying to activate? I tried that and it worked. – Reza Aghaei Aug 03 '16 at 21:45
  • Most likely you picked a non-focusable otherControl – Tim Copenhaver Aug 03 '16 at 21:52
  • I update the question with answers to your comments @LarsTech – Ayorus Aug 04 '16 at 14:07
  • You'd have to set the focus on a control that *wants* the focus. So just about none of the controls you listed. The most obvious way to tell that a control doesn't want focus is by not seeing that it has the focus when you click on it. – Hans Passant Aug 04 '16 at 14:11
  • So, I have a very nasty problem because there are no other focusable controls in the form. @HansPassant – Ayorus Aug 04 '16 at 14:28
  • Not exactly. It only becomes a problem when you keep jerking the focus away from the only control that the user ever wants to use. Don't create hostile UI and you'll be fine. – Hans Passant Aug 04 '16 at 14:32
  • Ok, I checked the form before selecting the toolstriptextbox (when everything works as expected) and the focus is assigned to the splitterPanel (i.e. form.ActiveControl). In fact, it seems, it is the only other control which can handle the focus. What I want to do is just remove the text cursor from the toolstriptextbox. Do you have any suggestion? @HansPassant – Ayorus Aug 04 '16 at 14:43

1 Answers1

-1

The following answer helpme to solve this problem: https://stackoverflow.com/a/1140277/2835505

What I did was to add an invisible label in the form. After the user is done updating the toolstriptextbox. I just focus on the new auxiliary label and it is done.

Thanks to all people who commented

Community
  • 1
  • 1
Ayorus
  • 477
  • 7
  • 16