-1

Possible Duplicate:
Setting external application focus

even know it DUPLICATE BUT it is different language. Some Pro. Programer will think is easy BUT not for beginner. Which don't have any knowledge about VB.

I'm making this application to check money from a card. It will list all the details pertaining to what they used it for and when. I will set up 1 PC with no keyboard and mouse, and it will automatically boot and shut down every day.

However, there is one problem. For example, I have TeamViewer and this application that I'm making. Both programs will start up when Windows boots. If my application starts up first, the textbox within will lose focus when TeamViewer starts.

I've already tried to use TopMost and ShowDialog, but when another application starts, the textbox still loses focus.

Any suggestions?

15
  • Set the color to look like focus. Why would you want this?
    – MoonKnight
    Jun 5, 2012 at 10:36
  • On lost focus give it focus again. Jun 5, 2012 at 10:39
  • What is your app ? and what is the other app which causes it to lose focus, can you edit and frame a proper question ?
    – V4Vendetta
    Jun 5, 2012 at 10:43
  • 1
    I think there is a misunderstanding about focus. You wrote "another application" the operating system makes sure that only ONE of the many applications running can have the focus, otherwise who would get the keyboard input for example. You have to live with the fact that your application can't and shouldn't have the focus all the time. But if it is about your own application and your other windows, there might be some solution. But even here i strongly advice you not to mess to much with focus handling.
    – dowhilefor
    Jun 5, 2012 at 10:51
  • @Keplah; there's no need to be personal. You can comment as others have and ask for clarification of the question. Down-vote if the question still makes no sense and ultimately flag for a moderator to take a look if you think it warrants it.
    – Ben
    Jun 5, 2012 at 15:39

1 Answer 1

4

You can try to use the LostFocus event and "re-focus" the TextBox:

textBox.LostFocus += new EventHandler((s, e) => textBox.Focus());

This doesn't work if your form and the parent controls aren't focused.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.