tags:

views:

1102

answers:

4
+1  A: 

You will have to sanitize the input.

Do not allow anchor or script tags or on attributes. (I don't know if you can disable javascript on the control, but that would be a good idea to.

EndangeredMassa
This won't work for my purpose. I want my users to create links. I just want to make sure the "preview" pane is a preview of the correct page.
Zack Peterson
Oh, I see. That's quite the pickle.
EndangeredMassa
+5  A: 

Can't you just place a transparent window over the entire control and capture all the mouse and keyboard events there?

Grant Wagner
+2  A: 

Maybe you can catch the control's click event and throw it away before it tries to navigate to the link? I'm not sure if it's possible but I'd try that.

Ricardo Villamil
The WebBrowser control has no Click event, but rather a Navigating event. See my answer for full solution.
Zack Peterson
+2  A: 

Capture the Navigating event of the WebBrowser control and set the Cancel property of its NavigatingCancelEventArgs to True.

Visual Basic code...

Private Sub WebBrowser1_Navigating(...) Handles WebBrowser1.Navigating
    If WebBrowser1Locked Then
        e.Cancel = True
    End If
End Sub

This requires a global locking boolean variable.

Partial Public Class Window1
    Dim WebBrowser1Locked As Boolean = True
    ...
End Class

And locking and unlocking to be wrapped around the desired navigation.

WebBrowser1Locked = False
WebBrowser1.NavigateToString("...")
WebBrowser1Locked = True
Zack Peterson