[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Showing a document on screen using wordviewer control

I need to show a document on screen as an order entry form is displayed. I want this document to appear as a separate form that can be resized and scrollable but that is all I want. I do not want the user to have access to saving, right clicking anything other than resizing or scrolling should be disabled. I have tried unsuccessfully to lock down wordviewer I am looking for other alternatives but if someone can post wordviewer code that will work I will use it.
     I need full code posted on whatever solution is generated, post the complete code to display a document in the webbrower control with only the scrollbars and resizing available to the user. No rightclick as well. Also the form needs to be resizable to the user.

below is what I have so far and is not working:

Private WithEvents MyDocument As HTMLDocument

Private Function MyDocument_oncontextmenu() As Boolean
    MyDocument_oncontextmenu = False
    PopupMenu MyPopupMenu
End Function

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Set MyDocument = WebBrowser1.Document
End Sub

Private Sub Form_Load()
    Form3.Caption = "This is a test"
    WebBrowser1.Navigate2 "\\Fserver1\common\ShowOnScreen.doc"
    WebBrowser1.Resizable = True
    WebBrowser1.MenuBar = False
    WebBrowser1.RegisterAsBrowser = False
    WebBrowser1.StatusBar = False
End Sub

Private Sub Command1_Click()
    WebBrowser1.Navigate2 "about:blank"
End Sub

Private Function webbrowser1_oncontextmenu() As Boolean
    webbrowser1_oncontextmenu = False
End Function
Private Sub cmdResize_Click()
    Form3.Top = 0
    Form3.Left = 0
    Form3.Width = Form3.WebBrowser1.Width
    Form3.Height = Form3.WebBrowser1.Height
    WebBrowser1.Refresh
End Sub

Private Sub Form3_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    OldX = x
    OldY = y
End Sub

Private Sub Form3_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim RectDiff As Double
    Dim NewLeft As Single
    Dim NewTop As Single
   
    If Button = 0 Then
        If y >= Form3.Height - 100 And x >= Form3.Width - 100 Then
            Form3.MousePointer = 8
            Exit Sub
        End If
        If x < Form3.Width And x >= Form3.Width - 100 Then Form3.MousePointer = 9
        If y < Form3.Height And y >= Form3.Height - 100 Then Form3.MousePointer = 7
   
        If y < Form3.Height - 100 And x < Form3.Width - 100 Then
            If Form3.Width > WebBrowser1.Width Or Form3.Height > WebBrowser1.Height Then
                Form3.MousePointer = 5
            Else
                Form3.MousePointer = 1
            End If
        End If
    End If

    If Button = 1 Then
        If Form3.MousePointer = 9 Then Form3.Width = x
        If Form3.MousePointer = 7 Then Form3.Height = y
        If Form3.MousePointer = 8 Then
            RectDiff = Form3.Width / Form3.Height
            If x <> Form3.Width Then
                Form3.Width = x
                Form3.Height = Form3.Width / RectDiff
                Exit Sub
            End If
        End If
       
        If Form3.MousePointer = 5 Then
            NewLeft = x - OldX + Form3.Left
            NewTop = y - OldY + Form3.Top
           
            If NewLeft > 0 Then NewLeft = 0
            If NewTop > 0 Then NewTop = 0
           
            'if image was moved to the left
            If Form3.Left + Form3.Width >= WebBrowser1.Width And NewLeft + Form3.Width < WebBrowser1.Width Then
                NewLeft = WebBrowser1.Width - Form3.Width
            End If
       
            If Form3.Top + Form3.Height >= WebBrowser1.Height And NewTop + Form3.Height < WebBrowser1.Height Then
                NewTop = WebBrowser1.Height - Form3.Height
            End If
           
            Form3.Move NewLeft, NewTop
        End If
    End If
End Sub

Private Sub Form3_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then
        Form3.Width = Form3.Width * 0.9
        Form3.Height = Form3.Height * 0.9
    End If
    WebBrowser1.Refresh
End Sub


0
Dalexan
Asked:
Dalexan
  • 4
  • 2
1 Solution
 
David LeeCommented:
The code you're using to prohibit right-clicking in the Webbrowser control is the same code I'd have proposed.  It works fine with HTML documents, but not with the Word viewer.  Do you have to use documents in Word format?  If you convert those same documents to HTML format, then this code would meet your needs.
0
 
DalexanAuthor Commented:
Can you post this code changed to work with an HTML control?
0
 
David LeeCommented:
Sure.  I used your code from above, only I passed it the name of an html file instead of a Word document.  I didn't play around with the rest of your code to see what it does since I'm assuming that killing the right-click functionality is the real issue.


Private WithEvents MyDocument As HTMLDocument

Private Function MyDocument_oncontextmenu() As Boolean
    MyDocument_oncontextmenu = False
    'I removed your line of code and inserted this line.
    'It pops a simple messagebox up telling the viewer that right-click is disabled.  
    'I put it in as a test to make sure things were working.  
    MsgBox "Right-click is disabled"
End Function

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Set MyDocument = WebBrowser1.Document
End Sub

Private Sub Form_Load()
    'Replace the path below with the path to an htm file on your network
    WebBrowser1.Navigate2 "\\Server\Share\Myfile.htm"
    WebBrowser1.Resizable = True
    WebBrowser1.MenuBar = False
    WebBrowser1.RegisterAsBrowser = False
    WebBrowser1.StatusBar = False
End Sub

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
David LeeCommented:
I object to closing the question.  The code I posted does what the asker indicated they wanted.  At the very least I'd like to know what was wrong with the solution I proposed, why it didn't work, etc.
0
 
DalexanAuthor Commented:
I dont understand please repost my code including your changes for this to work.
0
 
David LeeCommented:
Why would I need to repost the code?  It's in this thread, just scroll up and look at my post from 11/22/2004 at 10:15 AM.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now