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?
 
_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

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

regards,
Kate
0
 
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.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

button.SetStyle(ControlStyles.Selectable, false);

regards,
Kate
0
 
LawlessOneAuthor Commented:
This does exactly what I asked for... nice find Kate!

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

regards,
Kate
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.