How can I stretch picture to fit an option botton

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kabyr
    New Member
    • Nov 2007
    • 29

    #1

    How can I stretch picture to fit an option botton

    I have a form in my application where options are displayed to the user in form of images.

    I have created list of option buttons, set style to graphics and able to load pictures. My problem is that some pictures are either too big or too small to fit in the option boxes.

    Can somebody help me on how to stretch the picture to fit the option box? just like in image box.

    Thank you in advance.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    the idea is to load the file in a picture var, resise it in a (invisible) picturebox, put the image in the clipboard and put the clipboard in the option button with=

    You can change the size by changing paintpicture of picture1 AND the size of picture1.

    Code:
    Private Sub Command1_Click()
    Dim oPic As StdPicture
       On Error GoTo Error_Open_File
       With CommonDialog1
          .CancelError = True
          .Filter = "GIF (*.gif)|*.gif|JPG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|JPEG (*.JPEG)|*.JPEG"
          .InitDir = Environ$("USERPROFILE") & "\My Documents"
          .DialogTitle = "Open a file..."
          .ShowOpen
          Set oPic = LoadPicture(.FileName)
       End With
       On Error GoTo Error_Open_File
       With Picture1
          .Width = 1200 'change the size of the image canvas => picture in the optionbutton
          .Height = 1200 'change the size of the image canvas => picture in the optionbutton
          .AutoRedraw = True
          .PaintPicture oPic, 0, 0, 900, 900 'change the size of the image
           Clipboard.Clear
          Clipboard.SetData .Image, vbCFBitmap
       End With
       Option1.Picture = Clipboard.GetData(vbCFBitmap)
       Option1.Refresh
    Exit Sub
    Error_Open_File:
       MsgBox "There is an error opening the file"
    End Sub

    Comment

    • Guido Geurs
      Recognized Expert Contributor
      • Oct 2009
      • 767

      #3
      can also without clipboard=

      Code:
         With Picture1
            .Width = 1200 'change the size of the image canvas => picture in the optionbutton
            .Height = 1200 'change the size of the image canvas => picture in the optionbutton
            .AutoRedraw = True
            .PaintPicture oPic, 0, 0, 900, 900 'change the size of the image
            Option1.Picture = .Image
         End With

      Comment

      • Kabyr
        New Member
        • Nov 2007
        • 29

        #4
        Thanky ou GGEU for your brilliant idea. It was greately helpful.

        I chose to apply the image directly without using the clipboard. That reduced the process time.

        However, both procedures worked well.

        Thank you once again and to all purus here. Happy coding.
        Last edited by Kabyr; Aug 29 '10, 10:14 AM. Reason: typo error

        Comment

        Working...