Results 1 to 7 of 7

Thread: How can i stretch a picturebox?

  1. #1

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460

    How can i stretch a picturebox?

    How can i stretch the picture in a picturebox like i can in an imagecontrol?

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You could try using StretchBlt to blit to the picturebox
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    New Member
    Join Date
    Sep 2001
    Posts
    1

    repyl of your question

    in picturebox control set the property autosize=true.
    and in imagecontrol set the property stretch=true
    try this
    and enjoy your self

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: repyl of your question

    Originally posted by sipatel8
    in picturebox control set the property autosize=true.
    and in imagecontrol set the property stretch=true
    try this
    and enjoy your self
    The stretch property in the image control will stretch the picture to fix the control's size. The autosize property in the picturebox control will resize the picturebox to the size of the picture.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    plenderj>> Explain some more about Bitblt. Some code would be great.. Thank you..

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This should do it.
    Add a picturebox called Picture1, and a small picture called a.bmp in the root directory, and this should do it.

    VB Code:
    1. Private Declare Function StretchBlt Lib "GDI32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    2. Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hdc As Long) As Long
    3. Private Declare Function DeleteDC Lib "GDI32" (ByVal hdc As Long) As Long
    4. Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
    5. Private Declare Function DeleteObject Lib "GDI32" (ByVal hObject As Long) As Long
    6. Private Declare Function SelectObject Lib "GDI32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    7.  
    8. '' Device Contexts used for blitting
    9. Private myDc As Long
    10.  
    11. Private DC As Long
    12. Private picTemp As IPictureDisp
    13.  
    14. Private Sub Form_Load()
    15.     DC = CreateCompatibleDC(Form1.hdc)
    16.     If DC < 1 Then
    17.         Exit Sub
    18.     End If
    19.     Set picTemp = LoadPicture("c:\a.bmp")
    20.     SelectObject DC, picTemp
    21.     GenerateDC = DC
    22.     DeleteObject picTemp
    23.     myDc = DC
    24.    
    25.     StretchBlt Picture1.hdc, 0, 0, Picture1.Width, Picture1.Height, myDc, 0, 0, Form1.ScaleX(picTemp.Width), Form1.ScaleY(picTemp.Height), vbSrcCopy
    26.    
    27. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7

    Thread Starter
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Thanx!! Got it and run it..

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