Link to home
Start Free TrialLog in
Avatar of LawlessOne
LawlessOne

asked on

Prevent Button Focus vb.net VS 2008

I'm building a windows form, coding in vb.net with a webbrowser control and some buttons which I want to send keystrokes to various pages displayed in the wb control.

I created a solution which works except for with certain fields that validate on the html/javascript side when they lose focus. (setting focus and then sendkeys works otherwise).  That is, a field that checks for a valid amount or whatever, will check whenever the control loses focus and so my current solution will not work if the user happens to have entered an invalid value.

I cannot modify the web pages, or cause them to be modified.

My ideal solution would be creating the buttons on my form so that they never get focus, but can still be clicked.

The buttons are part of a panel on the same form as the webcontrol.
Avatar of _Katka_
_Katka_
Flag of Czechia image

Hi, did you try setting TabStop = false on those buttons.

regards,
Kate
Avatar of LawlessOne
LawlessOne

ASKER

Unfortunately that won't fix the problem... I think I'll need to override a method in a class that inherits from button or do some thread monitoring, but I need an example or some type of guidance for that.
Two more ideas:

1) maybe you could override the ProcessKeyMessage method on the form, and after each key press change the focus to a webbrowser component
2) or create and use a descendant of the WebBrowser control, and the hook its ProcessKeyMessage, and after the key is pressed set the focus to itself

Let me know how it went.

regards,
Kate
The problem though, is not getting focus set back to the right place - I've got that covered, and most of the time it is an adequate solution.  

However, in the case where a user puts invalid data in a field on a page in the WB control, and the field validates when focus is lost, then this solution is not going to work.  So as soon as the button is pressed, focus shifts and the validation fires off.

That's why I'm pursuing the "no focus" button solution.  I know how to build a form which does not gain focus, but not a button.
Ok, can't you do it differently, like a direct communication (HttpWebRequest) with that website, if it's only a few (not a general browser), instead of the relaying on the webbrowser. You chould just send the response which would fill the fields directly.

regards,
Kate
No, for our purposes that is not feasible.

If I'm unable to figure out how to create the "no focus" buttons on the same form I have an alternative which is much less optimal, but which still involves using buttons.

At this point I'm most interested in help in creating the buttons without the ability to gain focus, but thanks for your suggestions anyway, Kate!
Ok, I've found something, I'll give it a try on the test-form.

button.SetStyle(ControlStyles.Selectable, false);

regards,
Kate
ASKER CERTIFIED SOLUTION
Avatar of _Katka_
_Katka_
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This does exactly what I asked for... nice find Kate!

Thank you.
Thanks Kate
You're welcome. :)

regards,
Kate