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.
LawlessOneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

regards,
Kate
LawlessOneAuthor Commented:
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.
_Katka_Commented:
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
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

LawlessOneAuthor Commented:
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.
_Katka_Commented:
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
LawlessOneAuthor Commented:
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!
_Katka_Commented:
Ok, I've found something, I'll give it a try on the test-form.

button.SetStyle(ControlStyles.Selectable, false);

regards,
Kate
_Katka_Commented:
Yep, that works, but you've to make a descendant of the button.

regards,
Kate
public class MyButton : Button
    {
        public MyButton()
        {
            this.SetStyle(ControlStyles.Selectable, false);
        }
    }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LawlessOneAuthor Commented:
This does exactly what I asked for... nice find Kate!

Thank you.
LawlessOneAuthor Commented:
Thanks Kate
_Katka_Commented:
You're welcome. :)

regards,
Kate
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.