Learn how to a build a cloud-first strategyRegister Now

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

Resizing Webbrowser control at runtime

Can somebody provide the code (not a link) to enable a webbrowser control to be resized at runtime BUT NOT resizing the form? That is using the mouse to drag the webbrowser corners or sides but not changing the form size?  
0
NessieB
Asked:
NessieB
  • 2
  • 2
1 Solution
 
BurbbleCommented:
Do you want to be able to manipulate it just like a control in design time? Or only resize the lower-right corner / right side / bottom side?
0
 
GrahamSkanCommented:
This code could be improved, but is should give you the idea
Dim sX As Single
Dim zY As Single

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 And (X > WebBrowser1.Left + WebBrowser1.Width And X < WebBrowser1.Left + WebBrowser1.Width + 50 Or _
        Y > WebBrowser1.Top + WebBrowser1.Height And Y < WebBrowser1.Top + WebBrowser1.Height + 50) Then
        sX = X
        zY = Y
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If (X > WebBrowser1.Left + WebBrowser1.Width And X < WebBrowser1.Left + WebBrowser1.Width + 50 Or _
        Y > WebBrowser1.Top + WebBrowser1.Height And Y < WebBrowser1.Top + WebBrowser1.Height + 50) Then
        MousePointer = vbSizeNWSE
    Else
        MousePointer = vbDefault
    End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If sX <> 0 Or zY <> 0 Then
        With WebBrowser1
            .Height = Y - .Top
            .Width = X - .Left
        End With
        sX = 0
        zY = 0
    End If
End Sub

0
 
NessieBAuthor Commented:
I put a webbowser control on a form1 and pasted your code. The webbrowser1 jumps around the form it doesnt resize according to mousepointer position.

what is the precise coding for sX and sY please?
Dim sX As Single
Dim zY As Single
I dont think is correct, where should this go?

dragmode = vbAutomatic, should there be something else I need to add?

Can anybody help a newbie out?
0
 
GrahamSkanCommented:
I did say that it was simple. It will resize the Browser according to the movement of the mouse. But it doesn't differentiate between the right-side, bottom and corner actions. The control doesn't jump around on my system. (The top and left borders do not move)
I don't understand your problem with sX and sY. They are Single variables declared at form level.

dragmode is left as default

I didn't realise that you were a novice. I'll try to improve the code.
0
 
NessieBAuthor Commented:
graham - thanks I had a good look and I undestand what I did, so good job and enjoy the points!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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