I have a design on a form that has an MSFlexGrid on it. I can export the form as a BMP image but it won't include the MSFlexGrid on the exported image. How can I get the MSFlexGrid to be included in the exported BMP? At the moment it exports everything on the form, including the PictureBox and Command Button, but won't show the MSFlexGrid.
The form has a PictureBox (Picture1), an MSFlexGrid (VSFlexGrid1) and a command button (Command1).
For reference, here's my coding:
The form has a PictureBox (Picture1), an MSFlexGrid (VSFlexGrid1) and a command button (Command1).
For reference, here's my coding:
Code:
Option Explicit
Dim strClass, strBrand, strDesc, strSize, strOrganic, strGlutenFree, strUnit, strWSale, strGST, strCode, strFilename, strBarcode As String
Private Declare Function SendMessage Lib "user32.dll" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all owned windows
Public Sub SavePictureBox(PicBox As PictureBox, FileName As String)
Dim rv As Long
Dim ar As Boolean
With PicBox
'Save ReDraw value
ar = .AutoRedraw
.AutoRedraw = True
'Draw controls to picture box
rv = SendMessage(.hwnd, WM_PAINT, .hDC, 0)
rv = SendMessage(.hwnd, WM_PRINT, .hDC, _
PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
'save picture box
SavePicture .Image, FileName
.Cls
'Restore ReDraw
.AutoRedraw = ar
End With
End Sub
Private Sub Command1_Click()
SavePictureBox Picture1, "c:\test.bmp"
Unload Me
End
End Sub
Private Sub Form_Load()
Dim i As Integer ' i used for columns
Dim x As Integer ' x used for rows
With VSFlexGrid1
For x = 0 To .Rows - 1
.Row = x ' the row you want to highlight
For i = 0 To .Cols - 1 ' fill each cell in row (row width - 1)
.Col = i ' current column in row (=cell)
.CellBackColor = vbWhite ' fill all columns with white background
Next i
Next x
End With
SetHeading 0
LoadData
With VSFlexGrid1
.ColWidth(0) = 10545 ' Description
.ColWidth(1) = 1725 ' Size
.ColWidth(2) = 1785 ' Unit
.ColWidth(3) = 1905 ' Organic
.ColWidth(4) = 107 * 15 ' Gluten Free
.ColWidth(5) = 124 * 15 ' W/Sale
.ColWidth(6) = 104 * 15 ' GST
.ColWidth(7) = 271 * 15 ' Code
.ColWidth(8) = 226 * 15 ' Barcode
.ColWidth(9) = 69 * 15 ' Order Single Units 1
.ColWidth(10) = 69 * 15 ' Order Single Units 2
.ColWidth(11) = 69 * 15 ' Order Single Units 3
.ColWidth(12) = 69 * 15 ' Order Single Units 4
End With
End Sub
Private Sub SetHeading(RowNum As Integer)
Dim Count As Integer
With VSFlexGrid1
.Row = RowNum
For Count = 0 To .Cols - 1
.Col = Count
.CellBackColor = vbBlack
.CellFontSize = 51
.CellFontBold = True
.CellForeColor = vbWhite
.CellAlignment = 1
.CellFontItalic = True
.MergeCells = 2 ' Merge cells that contain the same value
.MergeRow(RowNum) = True ' Allow cells in row 0 to be merged
.RowHeight(RowNum) = 1150
.Text = UCase("brand heading here") ' Set all cells in row to same value : result is merged cells
Next Count
End With
End Sub
Private Sub LoadData()
Dim c As Integer
Open "C:\New Catalogue Data\NewCatalogueData - Ambient.csv" For Input As #5 ' Use #5 for catalogue data
For c = 1 To 19
Input #5, strClass, strBrand, strDesc, strSize, strOrganic, strGlutenFree, strUnit, strWSale, strGST, strCode, strFilename, strBarcode
With VSFlexGrid1
.TextMatrix(c, 0) = strDesc
.TextMatrix(c, 1) = strSize
.TextMatrix(c, 2) = strOrganic
.TextMatrix(c, 3) = strGlutenFree
.TextMatrix(c, 4) = strUnit
.TextMatrix(c, 5) = strWSale
.TextMatrix(c, 6) = strGST
.TextMatrix(c, 7) = strCode
.TextMatrix(c, 8) = strBarcode
End With
Next c
Close #5
End Sub