Solved

runtime resizing of picturebox

Posted on 1998-01-27
2
915 Views
Last Modified: 2010-05-18
Does anybody know if it's possible to allow a user to resize a picturebox at runtime? I'd like the user to click the corner and drag a band to the required size.
0
Comment
Question by:mark_s
2 Comments
 
LVL 8

Accepted Solution

by:
mrmick earned 100 total points
ID: 1453664
Sure, here's a rough sample of how to do it.  You can spice it up by changing the mouse pointer and/or limiting the minimum size, maximum size, etc...

Create a new project and place a single pictruebox (Picture1) on Form1 and paste the following code:

Dim Drag As Boolean
Dim DragX As Single, DragY As Single
Dim DragW As Single, DragH As Single

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Drag = True
DragX = X
DragY = Y
DragW = Picture1.Width
DragH = Picture1.Height
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Drag Then
Picture1.Width = DragW + (X - DragX)
Picture1.Height = DragH + (Y - DragY)
End If

End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Drag = False
End Sub

0
 

Expert Comment

by:Anoop
ID: 1453665
Almost all controls used in vb can be resized using windows API Call, Which I am Adding below
 This is coded in VB3.0 but can be updated for VB4.0 and VB5.0.

Global Const GWL_STYLE = (-16)
Global Const WS_THICKFRAME = &H40000
Global Const SWP_DRAWFRAME = &H20
Global Const SWP_NOMOVE = &H2
Global Const SWP_NOSIZE = &H1
Global Const SWP_NOZORDER = &H4

Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Long
Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
Declare Function SetWindowPOs Lib "User" (ByVal hwnd%, ByVal hWndInsertAfter%, ByVal x%, ByVal y%, ByVal cX%, ByVal cY%, ByVal wFlags%) As Integer



Sub Set_Sizable_Border (F_Controls As Control, F_Form As Form)
    Dim Style As Long, Ret As Integer
    Style = GetWindowLong(F_Controls.hWnd, GWL_STYLE)
    Style = Style Or WS_THICKFRAME
    Style = SetWindowLong(F_Controls.hWnd, GWL_STYLE, Style)
    Ret = SetWindowPOs(F_Controls.hWnd, F_Form.hWnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)
End Sub
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now