CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Posts
    1

    resize images in picture box

    I wish to put more than image in a picture box...and all image in the picture box are able to resize using mouse... do anyone got any idea for me to do this? please help!

    thanks
    Frankie


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: resize images in picture box

    Place several image boxes in a picturebox control. Set the Stretch property of each imagebox to true and load your pictures in these image boxes.

    Now, when you change the height and width properties of the imageboxes, the pictures will resize.

    Changing the size with the mouse (and you would want resizing handles too), it is a bit more complicated...


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: resize images in picture box

    Here is the complete form code from a project I churned out for you. Load your images in the two image boxes within the picture box.

    There is a picture box. Within it are two image boxes with the images and eight labels for the handles. You will ahve to work upon it to make it better.



    VERSION 5.00
    Begin VB.Form Form1
    Caption = "Form1"
    ClientHeight = 6660
    ClientLeft = 60
    ClientTop = 345
    ClientWidth = 7320
    LinkTopic = "Form1"
    ScaleHeight = 6660
    ScaleWidth = 7320
    StartUpPosition = 3 'Windows Default
    Begin VB.PictureBox Picture1
    Height = 5295
    Left = 600
    ScaleHeight = 5235
    ScaleWidth = 5235
    TabIndex = 1
    Top = 480
    Width = 5295
    Begin VB.Image imgPic
    Appearance = 0 'Flat
    BorderStyle = 1 'Fixed Single
    Height = 2415
    Index = 1
    Left = 960
    Picture = "Form1.frx":0000
    Stretch = -1 'true
    Top = 1920
    Width = 1935
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 7
    Left = 4080
    MousePointer = 8 'Size NW SE
    TabIndex = 9
    Top = 1080
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 6
    Left = 3720
    MousePointer = 7 'Size N S
    TabIndex = 8
    Top = 1080
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 5
    Left = 3480
    MousePointer = 6 'Size NE SW
    TabIndex = 7
    Top = 1080
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 4
    Left = 3120
    MousePointer = 9 'Size W E
    TabIndex = 6
    Top = 1080
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 3
    Left = 2880
    MousePointer = 9 'Size W E
    TabIndex = 5
    Top = 1080
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 2
    Left = 2640
    MousePointer = 6 'Size NE SW
    TabIndex = 4
    Top = 1080
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 1
    Left = 2520
    MousePointer = 7 'Size N S
    TabIndex = 3
    Top = 600
    Width = 90
    End
    Begin VB.Label lblHandle
    BackColor = &H00FF0000&
    ForeColor = &H00FF0000&
    Height = 90
    Index = 0
    Left = 240
    MousePointer = 8 'Size NW SE
    TabIndex = 2
    Top = 120
    Width = 90
    End
    Begin VB.Image imgPic
    Appearance = 0 'Flat
    BorderStyle = 1 'Fixed Single
    Height = 2415
    Index = 0
    Left = 360
    Picture = "Form1.frx":1026E
    Stretch = -1 'true
    Top = 240
    Width = 1935
    End
    End
    Begin VB.CommandButton Command1
    Caption = "Command1"
    Height = 495
    Left = 1560
    TabIndex = 0
    Top = 6240
    Width = 2295
    End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = false
    Attribute VB_Creatable = false
    Attribute VB_PredeclaredId = true
    Attribute VB_Exposed = false
    option Explicit

    Dim SelIndx as Integer

    private Sub PositionHandles(X1 as Integer, Y1 as Integer, X2 as Integer, Y2 as Integer, lblwid as Integer, lblhgt as Integer)
    Dim i as Integer

    lblHandle(0).Left = X1 - lblwid
    lblHandle(0).Top = Y1 - lblhgt
    lblHandle(1).Left = (X1 + X2 - lblwid) / 2
    lblHandle(1).Top = Y1 - lblhgt
    lblHandle(2).Left = X2
    lblHandle(2).Top = Y1 - lblhgt

    lblHandle(3).Left = X1 - lblwid
    lblHandle(3).Top = (Y1 + Y2 - lblhgt) / 2
    lblHandle(4).Left = X2
    lblHandle(4).Top = (Y1 + Y2 - lblhgt) / 2

    lblHandle(5).Left = X1 - lblwid
    lblHandle(5).Top = Y2
    lblHandle(6).Left = (X1 + X2 - lblwid) / 2
    lblHandle(6).Top = Y2
    lblHandle(7).Left = X2
    lblHandle(7).Top = Y2
    End Sub

    private Sub Form_Load()
    SelIndx = 0
    Call PositionHandles(imgPic(SelIndx).Left, imgPic(SelIndx).Top, imgPic(SelIndx).Left + imgPic(SelIndx).Width, imgPic(SelIndx).Top + imgPic(SelIndx).Height, 90, 90)
    End Sub

    private Sub imgPic_Click(Index as Integer)
    Call PositionHandles(imgPic(Index).Left, imgPic(Index).Top, imgPic(Index).Left + imgPic(Index).Width, imgPic(Index).Top + imgPic(Index).Height, 90, 90)
    SelIndx = Index
    imgPic(SelIndx).ZOrder
    End Sub

    private Sub lblHandle_MouseDown(Index as Integer, Button as Integer, Shift as Integer, X as Single, Y as Single)
    lblHandle(Index).Tag = X & " " & Y
    End Sub

    private Sub lblHandle_MouseUp(Index as Integer, Button as Integer, Shift as Integer, X as Single, Y as Single)
    Dim DiffX as Integer, DiffY as Integer
    DiffX = X - Val(Left$(lblHandle(Index).Tag, 5))
    DiffY = Y - Val(Right$(lblHandle(Index).Tag, 5))
    Select Case Index
    Case 0:
    With imgPic(SelIndx)
    .Move .Left - DiffX, .Top - DiffY, .Width + DiffX, .Height + DiffY
    End With
    Case 1:
    With imgPic(SelIndx)
    .Move .Left, .Top - DiffY, .Width, .Height + DiffY
    End With
    Case 2:
    With imgPic(SelIndx)
    .Move .Left, .Top - DiffY, .Width + DiffX, .Height + DiffY
    End With
    Case 3:
    With imgPic(SelIndx)
    .Move .Left - DiffX, .Top, .Width + DiffX, .Height
    End With
    Case 4:
    With imgPic(SelIndx)
    .Move .Left, .Top, .Width + DiffX, .Height
    End With
    Case 5:
    With imgPic(SelIndx)
    .Move .Left - DiffX, .Top, .Width, .Height + DiffY
    End With
    Case 6:
    With imgPic(SelIndx)
    .Move .Left, .Top, .Width, .Height + DiffY
    End With
    Case 7:
    With imgPic(SelIndx)
    .Move .Left, .Top, .Width + DiffX, .Height + DiffY
    End With
    End Select
    Call PositionHandles(imgPic(SelIndx).Left, imgPic(SelIndx).Top, imgPic(SelIndx).Left + imgPic(SelIndx).Width, imgPic(SelIndx).Top + imgPic(SelIndx).Height, 90, 90)
    End Sub





  4. #4
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: resize images in picture box

    Sorry. There was some mistake in the code I posted before.
    Replace lblHandle_MouseUp() with the code below.

    Also, in imgPic_Click() use
    imgPic(SelIndx).ZOrder 1
    if you want the sizing handles to show through at all times.


    private Sub lblHandle_MouseUp(Index as Integer, Button as Integer, Shift as Integer, X as Single, Y as Single)
    Dim DiffX as Integer, DiffY as Integer
    DiffX = X - Val(Left$(lblHandle(Index).Tag, 5))
    DiffY = Y - Val(Right$(lblHandle(Index).Tag, 5))
    Select Case Index
    Case 0:
    With imgPic(SelIndx)
    .Move .Left + DiffX, .Top + DiffY, .Width - DiffX, .Height - DiffY
    End With
    Case 1:
    With imgPic(SelIndx)
    .Move .Left, .Top + DiffY, .Width, .Height - DiffY
    End With
    Case 2:
    With imgPic(SelIndx)
    .Move .Left, .Top + DiffY, .Width + DiffX, .Height - DiffY
    End With
    Case 3:
    With imgPic(SelIndx)
    .Move .Left + DiffX, .Top, .Width - DiffX, .Height
    End With
    Case 4:
    With imgPic(SelIndx)
    .Move .Left, .Top, .Width + DiffX, .Height
    End With
    Case 5:
    With imgPic(SelIndx)
    .Move .Left + DiffX, .Top, .Width - DiffX, .Height + DiffY
    End With
    Case 6:
    With imgPic(SelIndx)
    .Move .Left, .Top, .Width, .Height + DiffY
    End With
    Case 7:
    With imgPic(SelIndx)
    .Move .Left, .Top, .Width + DiffX, .Height + DiffY
    End With
    End Select
    Call PositionHandles(imgPic(SelIndx).Left, imgPic(SelIndx).Top, imgPic(SelIndx).Left + imgPic(SelIndx).Width, imgPic(SelIndx).Top + imgPic(SelIndx).Height, 90, 90)
    End Sub






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured