Results 1 to 14 of 14

Thread: FlexGrid Pictures and Sizing [Resolved (Kinda)]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Resolved FlexGrid Pictures and Sizing [Resolved (Kinda)]

    Hello,

    I am trying to put a picture in a cell but it is too big and resizing the grid to accomodate the size of the picture is not an option.. What I want to do is resize the picture to fit inside the cell, how can I do that?

    thanks!

    - Quack!
    Last edited by Ogmius; Dec 8th, 2006 at 11:45 AM.
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: FlexGrid Pictures and Sizing

    would using a picturebox with .Visible = False and .AutoRedraw = True be an option:
    VB Code:
    1. Private Sub Command1_Click()
    2.     With MSFlexGrid1
    3.         .Col = 1
    4.         .Row = 1
    5.         Picture1.PaintPicture LoadPicture("C:\test.jpg"), 0, 0, .CellWidth, .CellHeight
    6.         Picture1.Picture = Picture1.Image
    7.         Set .CellPicture = Picture1.Picture
    8.         Set Picture1.Picture = Nothing
    9.     End With
    10. End Sub

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: FlexGrid Pictures and Sizing

    Quote Originally Posted by bushmobile
    would using a picturebox with .Visible = False and .AutoRedraw = True be an option:
    VB Code:
    1. Private Sub Command1_Click()
    2.     With MSFlexGrid1
    3.         .Col = 1
    4.         .Row = 1
    5.         Picture1.PaintPicture LoadPicture("C:\test.jpg"), 0, 0, [B][SIZE=3].CellWidth, .CellHeight[/SIZE][/B]
    6.         Picture1.Picture = Picture1.Image
    7.         Set .CellPicture = Picture1.Picture
    8.         Set Picture1.Picture = Nothing
    9.     End With
    10. End Sub
    I wouldn't agree with the highlighted - cell could be as wide as the entire form so can height.
    Image size needs to be calculated proportionally (basically scaled down) but based on "highlighted properties" vs original image size.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: FlexGrid Pictures and Sizing

    well the cells arent that large, but the pictures are pulled from an imagelist control, so I dont think that would work anyway
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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

    Re: FlexGrid Pictures and Sizing

    Quote Originally Posted by Ogmius
    well the cells arent that large, but the pictures are pulled from an imagelist control, so I dont think that would work anyway
    It will work like this:
    VB Code:
    1. 'Test this in a new project, Add a Picturebox and the Imagelist loaded with pictures.
    2. Private Sub Form_Load()
    3.     With Picture1
    4.         .Visible = False
    5.         .AutoRedraw = True
    6.         .BorderStyle = flexBorderNone
    7.     End With
    8. End Sub
    9.  
    10. Private Sub Command1_Click()
    11. Dim i As Long
    12.    
    13.     With MSFlexGrid1
    14.         .Rows = 2
    15.         .Cols = Me.Imagelist1.ListImages.Count
    16.         .Row = 1
    17.         For i = 1 To .Cols - 1
    18.             .Col = i
    19.             .CellPictureAlignment = flexAlignCenterCenter
    20.            
    21.             Picture1.Height = .CellHeight
    22.             Picture1.Width = .CellWidth
    23.            
    24.             ResizePicture Picture1, Me.Imagelist1.ListImages.Item(i).Picture
    25.             Set .CellPicture = Picture1.Image
    26.         Next
    27.     End With
    28. End Sub
    29.  
    30. Private Sub ResizePicture(pBox As PictureBox, pPic As Picture)
    31. Dim lWidth      As Single, lHeight    As Single
    32. Dim lnewWidth   As Single, lnewHeight As Single
    33.    
    34.     'Clear the Image  in the Picturebox
    35.     pBox.Cls
    36.    
    37.     'Get the size of the Image, but in the same Scale than the scale used by the PictureBox
    38.     lWidth = pBox.ScaleX(pPic.Width, vbHimetric, pBox.ScaleMode)
    39.     lHeight = pBox.ScaleY(pPic.Height, vbHimetric, pBox.ScaleMode)
    40.    
    41.     'If image Width > pictureBox Width, resize Width
    42.     If lWidth > pBox.ScaleWidth Then
    43.         lnewWidth = pBox.ScaleWidth              'new Width = PB width
    44.         lHeight = lHeight * (lnewWidth / lWidth) 'Risize Height keeping proportions
    45.     Else
    46.         lnewWidth = lWidth                       'If not, keep the original Width value
    47.     End If
    48.    
    49.     'If the image Height > The pictureBox Height, resize Height
    50.     If lHeight > pBox.ScaleHeight Then
    51.         lnewHeight = pBox.ScaleHeight                   'new Height = PB Height
    52.         lnewWidth = lnewWidth * (lnewHeight / lHeight)  'Risize Width keeping proportions
    53.     Else
    54.         lnewHeight = lHeight                            'If not, use the same value
    55.     End If
    56.    
    57.     'add resized and centered to Picturebox
    58.     pBox.PaintPicture pPic, (pBox.ScaleWidth - lnewWidth) / 2, _
    59.                             (pBox.ScaleHeight - lnewHeight) / 2, _
    60.                             lnewWidth, lnewHeight
    61. End Sub
    That code will fit the picture in the cell keeping ratio, but it won't make the picture bigger than its original size when its original size is smaller than the cell. Anyway, if you want to always resize (also in that cases) then this code can be easily modified to do that.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: FlexGrid Pictures and Sizing

    Quote Originally Posted by RhinoBull
    I wouldn't agree with the highlighted - cell could be as wide as the entire form so can height.
    Image size needs to be calculated proportionally (basically scaled down) but based on "highlighted properties" vs original image size.
    true - i just assumed Ogmius wanted to resize it to fill the cell, not resize it proportionally.

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: FlexGrid Pictures and Sizing

    Quote Originally Posted by Ogmius
    well the cells arent that large, but the pictures are pulled from an imagelist control, so I dont think that would work anyway
    Well, if you allow column rsizing then you cannot possibly know what it might be. That one thing. Another one is that you wouldn't want your users to see extremly distorted image or out of reasonable proportions, would you?

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: FlexGrid Pictures and Sizing

    That code looks great, im gonna have to use it next chance I get and let you know.. The cells are going to be a fixed size that cannot be changed, so as long as I can get one th work the rest will be great

    Thanks!
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  9. #9

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: FlexGrid Pictures and Sizing

    Ok, I did what you said, and the picture control works fine, but when it sets the cellpicture into the flexgrid I end up with no picture in the flexgrid...

    Below is the code, and I aslo attached a bmp of what it looks like

    VB Code:
    1. flxAgentList.Row = i
    2.         flxAgentList.Col = 0
    3.         flxAgentList.CellPictureAlignment = flexAlignCenterCenter
    4.         If flxAgentList.RowHeight(i) > flxAgentList.ColWidth(0) Then
    5.             Picture1.Height = flxAgentList.RowHeight(i)
    6.             Picture1.Width = flxAgentList.RowHeight(i)
    7.         Else
    8.             Picture1.Height = flxAgentList.ColWidth(0)
    9.             Picture1.Width = flxAgentList.ColWidth(0)
    10.         End If
    11.        
    12.         'Picture1.Picture = imgState.ListImages(Int(Mid(strAgentData, 1, InStr(1, strAgentData, "|", vbTextCompare) - 1))).Picture
    13.        
    14.         ResizePicture Picture1, imgState.ListImages(Int(Mid(strAgentData, 1, InStr(1, strAgentData, "|", vbTextCompare) - 1))).Picture
    15.        
    16.         Set flxAgentList.CellPicture = Picture1.Image
    17.         strAgentData = Mid(strAgentData, InStr(1, strAgentData, "|", vbTextCompare) + 1, Len(strAgentData))
    18.         flxAgentList.TextMatrix(i, 1) = Mid(strAgentData, 1, InStr(1, strAgentData, "|", vbTextCompare) - 1)
    19.         strAgentData = Mid(strAgentData, InStr(1, strAgentData, "|", vbTextCompare) + 1, Len(strAgentData))
    20.         flxAgentList.TextMatrix(i, 2) = Mid(strAgentData, 1, InStr(1, strAgentData, "|", vbTextCompare) - 1)
    21.         strAgentData = Mid(strAgentData, InStr(1, strAgentData, "|", vbTextCompare) + 1, Len(strAgentData))
    22.        
    23.         strAgentData = Mid(strAgentData, InStr(1, strAgentData, vbNewLine, vbTextCompare) + 2, Len(strAgentData))
    24.         i = i + 1
    25.         'flxAgentList.Rows = i + 1
    26.      Loop
    Attached Images Attached Images  
    Last edited by Ogmius; Dec 6th, 2006 at 02:35 PM.
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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

    Re: FlexGrid Pictures and Sizing

    That code looks ugly, and it's incomplete. Could you attach a project that demonstrates your problem? (zipped)

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: FlexGrid Pictures and Sizing

    Attached is the application, I changed the names of the people that im generating this for and removed the parts that add registry entries so that it doesnt put a bunch of crap on your PC...

    The modules are from other projects that I found on PlanetSourceCode and even here on VB Forums, I just havent had the chance to reference them in my project yet so if you wrote one of these, I Promise you will be acknowledged!


    If you click on the button that says "Agent View Test" it will do what its supposed to do, but it still has the bricks instead of the pictures... suggestions would be appreciated!

    Thanks in advance!
    Attached Files Attached Files
    Last edited by Ogmius; Dec 8th, 2006 at 10:30 AM.
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: FlexGrid Pictures and Sizing

    Bump... anyone?
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Location
    Manchester, CT
    Posts
    317

    Re: FlexGrid Pictures and Sizing [Resolved (Kinda)]

    I got it kinda... I decided to embed the proper size images into the application with an image list control instead of resizing them... its not the way I wanted to do it but it works and thats whats important
    "I dont even see the code anymore... I just see Blonde, Brunette, Redhead..."

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