C # WebBrowser prohibit F5 Refresh

Source: Internet
Author: User

In the process of writing a desktop software, use the WebBrowser to implement the interface. There is a requirement to prohibit WebBrowser from being refreshed via the F5 button. In the spirit of doing while learning principle, this dish checked Baidu, originally so simple, code as follows:

 This false;

Haha, success. Continue to complete the next task, write and write, found the wrong, very wrong. Just that code, not only the F5 this shortcut key disabled, and even CTRL + C, CTRL + V these shortcuts are prohibited. This is how it should be good. Then the first reflection of the dish: keyboard hooks. But then I thought, using C # also use hooks, obviously posture is not right ah. Well, not until the last resort, never use the hook treasure. Next, the dish has gone further and farther on the road of no return.

All over the street, string through the alley, over the Baidu, searched all over the Google, and finally even MSDN and open stack have been checked over. See the answer of the netizens: it is difficult to do, almost impossible. (See the Pit Daddy teammates are not confined to our side). Just as the dish to pick up the hook when the treasure, holding the last trace of the hope of struggle, turned over a WebBrowser function list, turned over, immediately before a bright, Qiang Qiang Qiang Qiang:

 Public classwebbroswer:system.windows.forms.webbrowser{ Publicwebbroswer ():Base()        {        }         Public Override BOOLpreProcessMessage (refMessage msg) {            Switch(Msg. MSG) { CaseApicaller.wm_keydown:intVK =Ptr.ptrtoint (Msg.                    WParam); if(VK = = the)return false;//Hook off F5                     Break; }            return Base. preProcessMessage (refmsg); }}

The main idea of this DAFA is to overload WebBrowser and dispose of F5 keyboard messages. (The Apicaller class in the code above is a custom class, just Judge Wm_keydown)

In fact, before this, the dish in WndProc and defwndproc between the two functions toss for a long time. Has not turned the corner, WebBrowser keyboard message wm_keydown, WM_KEYUP will not pass these two functions at all. Because before these two functions, they are distributed to the internal child controls. Fortunately, in time to wake up, this is completely eating no cultural loss, hope these experiences summary, can bring help to everyone. If this knowledge point is useful to you, please continue to propagate.

C # WebBrowser prohibit F5 Refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.