Solved

# Resizing Webbrowser control at runtime

Posted on 2005-05-08
266 Views
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
Question by:NessieB

LVL 7

Expert Comment

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

LVL 76

Accepted Solution

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

Author Comment

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

LVL 76

Expert Comment

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

Author Comment

graham - thanks I had a good look and I undestand what I did, so good job and enjoy the points!
0

## Featured Post

### Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…