Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

runtime resizing of picturebox

Posted on 1998-01-27
2
Medium Priority
?
925 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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
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…
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…
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…
Suggested Courses

636 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