"Block" a webbrowser object?

S

Sam

I am trying to create a webbrowser object that will a) not respond to clicks
on links, but b) will allow me to programatically navigate via the URL
property or Navigate() method.

I have tried to set AllowNavigation to false, but this restricts all
navigation, even by the methods and property.

I have also tried to use a boolean variable to indicate whether the
navigation request is "allowed" and cancel it in a Navigating event handler,
but I'm not sure where to reset the variable to not allow further
navigation. My first attempt was to do this in the DocumentCompleted event
handler, but I get multiple DocumentCompleted events on same web pages, so
if I clear the variable on the first DocumentCompleted, the further
navigations are cancelled... If I had a way to know when an "entire" page
was loaded, that might work, but I haven't found that event yet.

Is there a way to trap the mouse events within the webbrowser? Is there a
way to block them (I've thought of a transparent panel sitting in front of
the browser (not in front of the scroll bars, though!), but the transparency
doesn't seem to accomplish this.

Any ideas of how I can accomplish this?

Thanks in advance for any help you can provide!
 
M

mabster

This might be a terrible kludge compared to what you want, but could you
cancel *every* navigation, and simply write to the DocumentText
property? That way the WebBrowser never actually navigates. If you need
to show actual web pages then perhaps you could drag them down with a
WebClient object and pump in the HTML manually.
 
G

Guest

I am trying to create a webbrowser object that will a) not respond to clicks
on links, but b) will allow me to programatically navigate via the URL
property or Navigate() method.

I have no direct experience with what I am about to suggest, so use caution.
Maybe you could use the webbrowser's BeforeNavigate2 which allows for
cancellation of a navigation. Make a boolean variable indicating validity of
a navigation, and let its usual state be false. When the user tries to
navigate in a way that is ok with you, set it to true. In the event handler,
cancel the navigation or let it pass based on the validity flag. When the
navigation is complete or canceled, revert the flag to false.

This sounds plausible to me, but it is complicated by the fuzziness
webbrowser event sequencing. For example, maybe you will get two
BeforeNavigate2 events fired for one user navigation action. As I said, this
suggestion comes without any warranties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top