Results 1 to 3 of 3

Thread: picture box with scrollbar

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    278

    picture box with scrollbar

    hi all,

    1. how can i check the picture control is empty

    2. Is it possible to insert scroll bar(horizonatl and veritcal) with picture control so that i can scroll i see the complete image inserted


    thanks in advance

    saj

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: picture box with scrollbar

    1. To check if there is a picture in the Picturebox you can use..
    VB Code:
    1. If Picture1.Picture = 0 Then
    2.         MsgBox "No picture loaded"
    3.     Else
    4.         MsgBox "there is a picture loaded"
    5.     End If
    The image in the picturebox is different, it's always there but it's not possible to know if there is something drawn (image is not the same than picture here), the image contains what you draw or paint manually inside the picturebox canvas. The answer to your question (2) here uses the image, not the picture, but you can easily copy the image to picture:
    VB Code:
    1. Set Picture1.Picture = Picture1.Image

    2. Add a VScroll1 and a HScroll to your Form
    In this example i loaded the picture by code but it can be changed to work with a picture loaded in design mode.
    VB Code:
    1. Private mPic        As Picture
    2. Private mWidth      As Long
    3. Private mHeight     As Long
    4.  
    5. Private Sub Form_Load()
    6.     With Picture1
    7.         .ScaleMode = vbPixels
    8.         .AutoRedraw = True
    9.        
    10.         Set mPic = LoadPicture("D:\chory.jpg")  '(Load your picture in this line)
    11.        
    12.         mWidth = ScaleX(mPic.Width, vbHimetric, vbPixels)
    13.         mHeight = ScaleX(mPic.Height, vbHimetric, vbPixels)
    14.         .PaintPicture mPic, 0, 0
    15.     End With
    16.            
    17.     If mHeight > Picture1.ScaleHeight Then
    18.         With VScroll1
    19.             .Min = 0
    20.             .Max = mHeight - Picture1.ScaleHeight
    21.             .SmallChange = ((mHeight - Picture1.ScaleHeight) / 100) + 1
    22.             .LargeChange = ((mHeight - Picture1.ScaleHeight) / 10) + 1
    23.         End With
    24.     Else
    25.         VScroll1.Enabled = False
    26.     End If
    27.    
    28.     If mWidth > Picture1.ScaleWidth Then
    29.         With HScroll1
    30.             .Min = 0
    31.             .Max = mWidth - Picture1.ScaleWidth
    32.             .SmallChange = ((mWidth - Picture1.ScaleWidth) / 100) + 1
    33.             .LargeChange = ((mWidth - Picture1.ScaleWidth) / 10) + 1
    34.         End With
    35.     Else
    36.         HScroll1.Enabled = False
    37.     End If
    38. End Sub
    39.  
    40. Private Sub HScroll1_Change()
    41.     RedrawPic
    42. End Sub
    43.  
    44. Private Sub VScroll1_Change()
    45.     RedrawPic
    46. End Sub
    47.  
    48. Private Sub RedrawPic()
    49.     With Picture1
    50.         .Cls
    51.         .PaintPicture mPic, -HScroll1.Value, -VScroll1.Value
    52.     End With
    53. End Sub
    Last edited by jcis; Dec 28th, 2006 at 09:00 AM.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Lightbulb Re: picture box with scrollbar

    Quote Originally Posted by sajankk
    1. how can i check the picture control is empty
    If Picture1.Picture.Width = 0 Then 'Empty

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