Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a browser that prevents the user from viewing the URL in Visual Basic .NET
DescriptionThis example shows how to make a browser that prevents the user from viewing the URL in Visual Basic .NET
Keywordsbrowser, URL, restricted browser, hide URL, VB.NET
CategoriesInternet, VB.NET
 
I had a customer that wanted to allow the user to visit a Web site but not to easily see what URL it was. The program must stop the user from right-clicking on the form to view the page's properties, which include the URL.

This program uses a form that contains a WebBrowser control. The form's ShowBrowser command displays the form. It adds the form as a message filter (the form must implement IMessageFilter to be a filter), navigates the the desired URL, and displays itself.

 
' Install ourself as a message filter.
Public Sub ShowBrowser(ByVal url As String, ByVal _
    show_modal As Boolean)
    ' Add a message filter.
    Application.AddMessageFilter(Me)

    ' Navigate to the URL.
    webRestricted.Navigate(url)

    If show_modal Then
        Me.ShowDialog()
    Else
        Me.Show()
    End If
End Sub
 
When the form receives a message, the PreFilterMessage function executes. The version here (adapted from http://www.freevbcode.com/ShowCode.asp?ID=5635) returns True for various special keys such as BrowserBack and the right-click to indicate that the message has been handled and should not be passed on to the WebBrowser control.
 
' WebBrowser adapted code from:
'   http://www.freevbcode.com/ShowCode.asp?ID=5635
Private Bstop As Boolean
Public Function PreFilterMessage(ByRef m As _
    System.Windows.Forms.Message) As Boolean Implements _
    IMessageFilter.PreFilterMessage
    ' WM_KEYDOWN As Int32 = &H100 Private Const WM_KEYUP As
     ' Int32 = &H101  WM_SYSKEYDOWN As Integer = &H104
    Dim keyCode As Keys = CType(m.WParam.ToInt32(), Keys) _
        And Keys.KeyCode
    Static ControlP As Boolean
    Select Case keyCode
        Case Keys.BrowserBack : Return True
        Case Keys.BrowserFavorites : Return True
        Case Keys.BrowserForward : Return True
        Case Keys.BrowserHome : Return True
        Case Keys.BrowserRefresh : Return True
        Case Keys.BrowserSearch : Return True
        Case Keys.BrowserStop : Return True

        Case Keys.RButton : Return True 'right mousebutton
        Case Keys.Back ' backspace key to handle history -1
            If m.Msg = &H100 Then
                Bstop = True 'stop this bb event !
            Else
                Bstop = False
            End If
        Case Keys.F5 : Return True ' no refresh 
        Case Keys.ControlKey ' control down ? then bypass P
             ' key
            If m.Msg = &H100 Then
                ControlP = True
            Else
                ControlP = False
            End If
        Case Keys.P
            If ControlP Then Return True
        Case Else
            If m.Msg = &H104 Then ' no more ALT shortcuts (
                 ' alt F4 etc etc )
                Return True
            End If
    End Select
End Function
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated