Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1512

MSFlexGrid: The power of the FillStyle property

$
0
0
Using the FillStyle property you can change a range of cells with a single command.
But you always have to take care about the current selected row, col, rowsel and colsel properties.
That's why I wrote a generic function which is capable of changing most of the cell properties with a single command.

Code:

'---------------------------------------------------------------------------------------
' Author    : Arnoutdv/Flyuy
' Original  : http://web.archive.org/web/20150531180340/http://www.xtremevbtalk.com/showthread.php?p=824613#post824613
'---------------------------------------------------------------------------------------
Option Explicit

Private Enum FGCellStyle
  fgcsBackColor = 1
  fgcsForeColor = 2
  fgcsText = 3
  fgcsTextStyle = 4
  fgcsFontName = 5
  fgcsFontBold = 6
  fgcsFontItalic = 7
  fgcsAllignment = 8
End Enum

Private Sub Form_Load()
  With MSFlexGrid1
    .Cols = 10
    .Rows = 10
  End With
 
  FG_Cell MSFlexGrid1, fgcsBackColor, 1, 1, 7, 7, RGB(191, 191, 255)
  FG_Cell MSFlexGrid1, fgcsBackColor, 3, 2, 7, 5, vbGreen
  FG_Cell MSFlexGrid1, fgcsForeColor, 1, 4, 3, 6, vbRed
  FG_Cell MSFlexGrid1, fgcsText, 1, 1, 5, 5, "Hello"
  FG_Cell MSFlexGrid1, fgcsFontBold, 2, 3, 5, 6, True
  FG_Cell MSFlexGrid1, fgcsAllignment, 2, 4, 3, 4, flexAlignRightCenter
  FG_Cell MSFlexGrid1, fgcsFontName, 1, 3, 2, 5, "Arial"
  FG_Cell MSFlexGrid1, fgcsTextStyle, 1, 1, 3, 3, flexTextRaised
End Sub

Private Sub FG_Cell(FG As MSFlexGrid, ByVal What As FGCellStyle, Row1 As Long, Col1 As Long, Row2 As Long, Col2 As Long, Value As Variant)
  Dim PrevRowCol(3) As Long    ' to store the actual settings
  Dim PrevFillStyle As Integer ' to store the actual settings
 
  With FG
    .Redraw = False
   
    ' Store current settings
    PrevFillStyle = .FillStyle
    PrevRowCol(0) = .Row:    PrevRowCol(2) = .RowSel
    PrevRowCol(1) = .Col:    PrevRowCol(3) = .ColSel
   
    ' Set the range
    .FillStyle = flexFillRepeat
    .Row = Row1:    .Col = Col1
    .RowSel = Row2: .ColSel = Col2
   
    ' Apply changes
    Select Case What
      Case fgcsBackColor:    .CellBackColor = Value
      Case fgcsForeColor:    .CellForeColor = Value
      Case fgcsText:        .Text = Value
      Case fgcsTextStyle:    .CellTextStyle = Value
      Case fgcsFontName:    .CellFontName = Value
      Case fgcsFontBold:    .CellFontBold = Value
      Case fgcsFontItalic:  .CellFontItalic = Value
      Case fgcsAllignment:  .CellAlignment = Value
    End Select
   
    ' Restore settings
    .FillStyle = PrevFillStyle
    .Row = PrevRowCol(0):    .Col = PrevRowCol(1)
    .RowSel = PrevRowCol(2): .ColSel = PrevRowCol(3)
   
    .Redraw = True
  End With
End Sub

Attached Images
 

Viewing all articles
Browse latest Browse all 1512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>