Solved

runtime resizing of picturebox

Posted on 1998-01-27
2
920 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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