Solved

runtime resizing of picturebox

Posted on 1998-01-27
2
921 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

696 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