VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Prints MSFlexGrid to a PictureBox Or Printer.

by Ali Atiq (Bahrain - Arab Gulf) (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Thu 2nd January 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Prints MSFlexGrid to a PictureBox Or Printer.

Rate Prints MSFlexGrid to a PictureBox Or Printer.




Dim CellX     As Single
Dim CellY     As Single
Dim CellW     As Single
Dim CellH     As Single
Dim CurX      As Single
Dim CurY      As Single
Dim CellStr   As String

Private Sub Combo1_Click()
  PrintFlex MSFlexGrid1, Picture1 'Print Flex Grid to picture
End Sub

Private Sub Form_Load()
  Dim i
  Combo1.Move 0, 0
  Combo1.AddItem "flexAlignLeftTop"
  Combo1.AddItem "flexAlignLeftCenter"
  Combo1.AddItem "flexAlignLeftBottom"
  Combo1.AddItem "flexAlignCenterTop"
  Combo1.AddItem "flexAlignCenterCenter"
  Combo1.AddItem "flexAlignCenterBottom"
  Combo1.AddItem "flexAlignRightTop"
  Combo1.AddItem "flexAlignRightCenter"
  Combo1.AddItem "flexAlignRightBottom"
  Combo1.AddItem "flexAlignGeneral"
  
  MSFlexGrid1.Cols = 6
  For i = 0 To 3
    MSFlexGrid1.AddItem i & Chr(9) & "String" & Chr(9) & i
  Next i
End Sub

Private Sub Form_Resize()
  MSFlexGrid1.Move 0, Combo1.Height, ScaleWidth / 2, ScaleHeight
  Picture1.Move ScaleWidth / 2, Combo1.Height, ScaleWidth / 2, ScaleHeight
End Sub

'Print from MSFlexGrid cells to either Printer Or Picture Box
Private Function PrintFlex(msflex As MSFlexGrid, Objct As Object)
  Dim r, c
  
  Objct.Cls
  For r = 1 To msflex.Rows - 1
    For c = 1 To msflex.Cols - 1
    
      CellX = msflex.ColPos(c)
      CellY = msflex.RowPos(r)
      CellW = msflex.ColWidth(c)
      CellH = msflex.RowHeight(r)
      Objct.Line (CellX, CellY)-(CellX + CellW, CellY + CellH), , B
      
      CellStr = msflex.TextMatrix(r, c)
      
      Select Case Combo1.ListIndex  'msflex.CellAlignment
        Case 0 'flexAlignLeftTop  (Left Top)
          CurX = CellX + 50
          CurY = CellY + 50
        Case 1 'flexAlignLeftCenter  (Left Center   (default for strings))
          LeftCenter
        Case 2 'flexAlignLeftBottom  (Left Bottom)
          LeftBottom
        Case 3 'flexAlignCenterTop  (Center Top)
          CenterTop
        Case 4 'flexAlignCenterCenter  (Center Center)
          CenterCenter
        Case 5 'flexAlignCenterBottom  (Center Bottom)
          CenterBottom
        Case 6 'flexAlignRightTop  (Right Top)
          RightTop
        Case 7 'flexAlignRightCenter  (Right Center   (default for numbers))
          RightCenter
        Case 8 'flexAlignRightBottom  (Right Bottom)
          RightBottom
        Case 9 'flexAlignGeneral  (General: Left Center for strings, Right  Center for numbers)
          General
      End Select
      Objct.CurrentX = CurX
      Objct.CurrentY = CurY
      Objct.Print CellStr
    Next c
  Next r
End Function

Sub LeftTop()
  CurX = CellX + 50
  CurY = CellY + 50
End Sub

Sub LeftCenter()
  CurX = CellX + 50
  CurY = CellY + ((CellH / 2) - (TextHeight(CellStr) / 2))
End Sub

Sub LeftBottom()
  CurX = CellX + 50
  CurY = CellY + (CellH - ((TextHeight(CellStr)) + 50))
End Sub

Sub CenterTop()
  CurX = ((CellW / 2) - (TextWidth(CellStr) / 2)) + CellX
  CurY = CellY + 50
End Sub

Sub CenterCenter()
  CurX = ((CellW / 2) - (TextWidth(CellStr) / 2)) + CellX
  CurY = ((CellH / 2) - (TextHeight(CellStr) / 2)) + CellY
End Sub

Sub CenterBottom()
  CurX = ((CellW / 2) - (TextWidth(CellStr) / 2)) + CellX
  CurY = (CellH - TextHeight(CellStr)) + CellY
End Sub

Sub RightTop()
  CurX = (((CellW - TextWidth(CellStr))) - 50) + CellX
  CurY = CellY + 50
End Sub

Sub RightCenter()
  CurX = (((CellW - TextWidth(CellStr))) - 50) + CellX
  CurY = ((CellH / 2) - (TextHeight(CellStr) / 2)) + CellY
End Sub

Sub RightBottom()
  CurX = (((CellW - TextWidth(CellStr))) - 50) + CellX
  CurY = (CellH - TextHeight(CellStr)) + CellY
End Sub

'flexAlignGeneral (General: Left Center for strings, Right  Center for numbers)
Sub General()
  If IsNumeric(CellStr) Then 'If contain numeric
    RightCenter
  Else 'Contain strings
    LeftCenter
  End If
End Sub

Download this snippet    Add to My Saved Code

Prints MSFlexGrid to a PictureBox Or Printer. Comments

No comments have been posted about Prints MSFlexGrid to a PictureBox Or Printer.. Why not be the first to post a comment about Prints MSFlexGrid to a PictureBox Or Printer..

Post your comment

Subject:
Message:
0/1000 characters