-
resize a picture or image box
Hello!
Can you help me on resizing a picture or image box by dragging the mouse
instead of coding the value. I'll be needing it on my application.
Thanks,
Rally
-
Re: resize a picture or image box
You can use small black pictureboxes for the size handles. Give them
the appropriate mousepointers for where you plan to put them. In the
example below, I have one size handle (Picture2) at the bottom right
corner of a picturebox (Picture1) that I want to resize.
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_NCLBUTTONDOWN = &HA1
Const HTBOTTOMRIGHT = 17
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
'resize picture1
ReleaseCapture
SendMessage Picture1.hwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, 0
End Sub
It practically seems like magic! You also need this code:
Private Sub Picture1_Resize()
'move the grab handle
Picture2.Move Picture1.Left + Picture1.Width, Picture1.Top +
Picture1.Height
End Sub
in order to keep the grab handle at the corner of Picture1 (you might have
to
modify it depending on your container hierarchy).
Here's some more constants that'll help you put handles in other
positions. Good Luck!
Jim Deutch
MS Dev MVP
' * WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
' */
#define HTERROR (-2)
#define HTTRANSPARENT (-1)
#define HTNOWHERE 0
#define HTCLIENT 1
#define HTCAPTION 2
#define HTSYSMENU 3
#define HTGROWBOX 4
#define HTSIZE HTGROWBOX
#define HTMENU 5
#define HTHSCROLL 6
#define HTVSCROLL 7
#define HTMINBUTTON 8
#define HTMAXBUTTON 9
#define HTLEFT 10
#define HTRIGHT 11
#define HTTOP 12
#define HTTOPLEFT 13
#define HTTOPRIGHT 14
#define HTBOTTOM 15
#define HTBOTTOMLEFT 16
#define HTBOTTOMRIGHT 17
#define HTBORDER 18
#define HTREDUCE HTMINBUTTON
#define HTZOOM HTMAXBUTTON
#define HTSIZEFIRST HTLEFT
#define HTSIZELAST HTBOTTOMRIGHT
#if(WINVER >= 0x0400)
#define HTOBJECT 19
#define HTCLOSE 20
#define HTHELP 21
Rally wrote in message <395b80da$1@news.devx.com>...
>
>Hello!
>
>Can you help me on resizing a picture or image box by dragging the mouse
>instead of coding the value. I'll be needing it on my application.
>
>Thanks,
>
>Rally
-
Re: resize a picture or image box
You can use small black pictureboxes for the size handles. Give them
the appropriate mousepointers for where you plan to put them. In the
example below, I have one size handle (Picture2) at the bottom right
corner of a picturebox (Picture1) that I want to resize.
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_NCLBUTTONDOWN = &HA1
Const HTBOTTOMRIGHT = 17
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
'resize picture1
ReleaseCapture
SendMessage Picture1.hwnd, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, 0
End Sub
It practically seems like magic! You also need this code:
Private Sub Picture1_Resize()
'move the grab handle
Picture2.Move Picture1.Left + Picture1.Width, Picture1.Top +
Picture1.Height
End Sub
in order to keep the grab handle at the corner of Picture1 (you might have
to
modify it depending on your container hierarchy).
Here's some more constants that'll help you put handles in other
positions. Good Luck!
Jim Deutch
MS Dev MVP
' * WM_NCHITTEST and MOUSEHOOKSTRUCT Mouse Position Codes
' */
#define HTERROR (-2)
#define HTTRANSPARENT (-1)
#define HTNOWHERE 0
#define HTCLIENT 1
#define HTCAPTION 2
#define HTSYSMENU 3
#define HTGROWBOX 4
#define HTSIZE HTGROWBOX
#define HTMENU 5
#define HTHSCROLL 6
#define HTVSCROLL 7
#define HTMINBUTTON 8
#define HTMAXBUTTON 9
#define HTLEFT 10
#define HTRIGHT 11
#define HTTOP 12
#define HTTOPLEFT 13
#define HTTOPRIGHT 14
#define HTBOTTOM 15
#define HTBOTTOMLEFT 16
#define HTBOTTOMRIGHT 17
#define HTBORDER 18
#define HTREDUCE HTMINBUTTON
#define HTZOOM HTMAXBUTTON
#define HTSIZEFIRST HTLEFT
#define HTSIZELAST HTBOTTOMRIGHT
#if(WINVER >= 0x0400)
#define HTOBJECT 19
#define HTCLOSE 20
#define HTHELP 21
Rally wrote in message <395b80da$1@news.devx.com>...
>
>Hello!
>
>Can you help me on resizing a picture or image box by dragging the mouse
>instead of coding the value. I'll be needing it on my application.
>
>Thanks,
>
>Rally
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks