home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Basic / GridOne / setup.EXE / FORM1.VB < prev    next >
Encoding:
Text File  |  2001-09-09  |  21.2 KB  |  577 lines

  1. '-----------------------------------------------------------------------------
  2. ' This is a part of the BeeGrid ActiveX control.
  3. ' Copyright ⌐ 2000 Stinga
  4. ' All rights reserved.
  5. '
  6. ' You have a right to use and distribute the BeeGrid sample files in original
  7. ' form or modified, provided that you agree that Stinga has no warranty,
  8. ' obligations, or liability for any sample application files.
  9. '-----------------------------------------------------------------------------
  10. Imports System.ComponentModel
  11. Imports System.Drawing
  12. Imports System.WinForms
  13. Imports BeeGridOLEDB10
  14. Imports Microsoft.VisualBasic.Compatibility.VB6
  15. Imports System.UInt32
  16. #Region "BeeGrid constants import"
  17. Imports BeeGridOLEDB10.sgAppearance
  18. Imports BeeGridOLEDB10.sgAlignment
  19. Imports BeeGridOLEDB10.sgAutoResize
  20. Imports BeeGridOLEDB10.sgButtonAlignment
  21. Imports BeeGridOLEDB10.sgCalculationType
  22. Imports BeeGridOLEDB10.sgCellBkgStyle
  23. Imports BeeGridOLEDB10.sgCellBorder
  24. Imports BeeGridOLEDB10.sgCellBorderStyle
  25. Imports BeeGridOLEDB10.sgCellEditorType
  26. Imports BeeGridOLEDB10.sgCellKind
  27. Imports BeeGridOLEDB10.sgCellMerge
  28. Imports BeeGridOLEDB10.sgCellStatus
  29. Imports BeeGridOLEDB10.sgCellTip
  30. Imports BeeGridOLEDB10.sgConditionValueSource
  31. Imports BeeGridOLEDB10.sgDataFormat
  32. Imports BeeGridOLEDB10.sgCustomDrawStage
  33. Imports BeeGridOLEDB10.sgCustomDrawResponse
  34. Imports BeeGridOLEDB10.sgDataMode
  35. Imports BeeGridOLEDB10.sgDataType
  36. Imports BeeGridOLEDB10.sgDisplayType
  37. Imports BeeGridOLEDB10.sgEllipsis
  38. Imports BeeGridOLEDB10.sgEnterKeyBehavior
  39. Imports BeeGridOLEDB10.sgEvenOddStyle
  40. Imports BeeGridOLEDB10.sgExpand
  41. Imports BeeGridOLEDB10.sgExportFlag
  42. Imports BeeGridOLEDB10.sgFilterAction
  43. Imports BeeGridOLEDB10.sgFocusRect
  44. Imports BeeGridOLEDB10.sgGridBorderStyle
  45. Imports BeeGridOLEDB10.sgGridHitTest
  46. Imports BeeGridOLEDB10.sgGridLineStyle
  47. Imports BeeGridOLEDB10.sgGridRedrawCode
  48. Imports BeeGridOLEDB10.sgGroupFooterText
  49. Imports BeeGridOLEDB10.sgGroupHeaderPicture
  50. Imports BeeGridOLEDB10.sgGroupHeaderText
  51. Imports BeeGridOLEDB10.sgGroupOperation
  52. Imports BeeGridOLEDB10.sgInactiveSelection
  53. Imports BeeGridOLEDB10.sgItemHeight
  54. Imports BeeGridOLEDB10.sgLayoutFormat
  55. Imports BeeGridOLEDB10.sgMaskDataMode
  56. Imports BeeGridOLEDB10.sgMousePointer
  57. Imports BeeGridOLEDB10.sgMultiSelect
  58. Imports BeeGridOLEDB10.sgNavigationWrapMode
  59. Imports BeeGridOLEDB10.sgNewRowPos
  60. Imports BeeGridOLEDB10.sgOLEDragMode
  61. Imports BeeGridOLEDB10.sgOLEDropMode
  62. Imports BeeGridOLEDB10.sgOperator
  63. Imports BeeGridOLEDB10.sgOutlineLines
  64. Imports BeeGridOLEDB10.sgPicAlignment
  65. Imports BeeGridOLEDB10.sgPopupAlignment
  66. Imports BeeGridOLEDB10.sgPreviewPanePosition
  67. Imports BeeGridOLEDB10.sgPreviewPaneType
  68. Imports BeeGridOLEDB10.sgRangeType
  69. Imports BeeGridOLEDB10.sgResizeAnimation
  70. Imports BeeGridOLEDB10.sgRowStatus
  71. Imports BeeGridOLEDB10.sgRowType
  72. Imports BeeGridOLEDB10.sgScrollBar
  73. Imports BeeGridOLEDB10.sgScrollBarMode
  74. Imports BeeGridOLEDB10.sgScrollTip
  75. Imports BeeGridOLEDB10.sgSearchFlag
  76. Imports BeeGridOLEDB10.sgSelectionMode
  77. Imports BeeGridOLEDB10.sgShowButton
  78. Imports BeeGridOLEDB10.sgSortOrder
  79. Imports BeeGridOLEDB10.sgSortType
  80. Imports BeeGridOLEDB10.sgSpecialMode
  81. Imports BeeGridOLEDB10.sgTabKeyBehavior
  82. Imports BeeGridOLEDB10.sgUserResizing
  83. Imports BeeGridOLEDB10.sgUserRowColDrag
  84. Imports BeeGridOLEDB10.sgUserRowColHide
  85. #End Region
  86.  
  87. Public Class Form1
  88. #Region "Declaration section"
  89.     Inherits System.WinForms.Form
  90.     
  91.     Private mlColCount As Integer
  92.     Private mlRowCount As Integer
  93.     Private mlMinesCount As Integer
  94.     Private Const SGM_CELL_SIZE As Short = 16 '305
  95.     
  96.     Private Const MAX_WIDTH As Short = 20
  97.     Private Const MAX_HEIGHT As Short = 20
  98.     Private Const MIN_MINES As Short = 5
  99.     
  100.     Private Const ID_MINE As Short = 9
  101.     Private Const ID_FLAG As Short = 10
  102.     Private Const ID_NOMINE As Short = 11
  103.     
  104.     Private vbButtonFace As UInt32
  105.     
  106.     Private mdtStartTime As Date
  107.     
  108.     Private Enum enmPictureIds
  109.         enmFlag = 8
  110.         enmMine = 9
  111.         enmNoMine = 10
  112.     End Enum
  113. #End Region
  114.     Public Sub New()
  115.         MyBase.New()
  116.         
  117.         Form1 = Me
  118.         
  119.         'This call is required by the Win Form Designer.
  120.         InitializeComponent()
  121.         
  122.         'TODO: Add any initialization after the InitializeComponent() call
  123.     End Sub
  124.     
  125.     'Form overrides dispose to clean up the component list.
  126.     Public Overrides Sub Dispose()
  127.         MyBase.Dispose()
  128.         components.Dispose()
  129.     End Sub
  130.     
  131. #Region " Windows Form Designer generated code "
  132.     
  133.     'Required by the Windows Form Designer
  134.     Private components As System.ComponentModel.Container
  135.     
  136.     
  137.     Private WithEvents ImageList1 As System.WinForms.ImageList
  138.     Private WithEvents txtRowCount As System.WinForms.TextBox
  139.     Private WithEvents txtColCount As System.WinForms.TextBox
  140.     Private WithEvents txtMines As System.WinForms.TextBox
  141.     Private WithEvents lblRows As System.WinForms.Label
  142.     Private WithEvents lblColumns As System.WinForms.Label
  143.     Private WithEvents lblMines As System.WinForms.Label
  144.     Private WithEvents cmdGame As System.WinForms.Button
  145.     Private WithEvents AxSGGrid1 As AxBeeGridOLEDB10.AxSGGrid
  146.     
  147.     Dim WithEvents Form1 As System.WinForms.Form
  148.     
  149.     'NOTE: The following procedure is required by the Windows Form Designer
  150.     'It can be modified using the Windows Form Designer.  
  151.     'Do not modify it using the code editor.
  152.     Private Sub InitializeComponent()
  153.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
  154.         
  155.         Me.components = New System.ComponentModel.Container()
  156.         Me.txtMines = New System.WinForms.TextBox()
  157.         Me.cmdGame = New System.WinForms.Button()
  158.         Me.txtRowCount = New System.WinForms.TextBox()
  159.         Me.lblRows = New System.WinForms.Label()
  160.         Me.lblColumns = New System.WinForms.Label()
  161.         Me.lblMines = New System.WinForms.Label()
  162.         Me.ImageList1 = New System.WinForms.ImageList()
  163.         Me.AxSGGrid1 = New AxBeeGridOLEDB10.AxSGGrid()
  164.         Me.txtColCount = New System.WinForms.TextBox()
  165.         
  166.         AxSGGrid1.BeginInit()
  167.         
  168.         '@design Me.TrayHeight = 90
  169.         '@design Me.TrayLargeIcon = False
  170.         '@design Me.TrayAutoArrange = True
  171.         txtMines.Location = New System.Drawing.Point(56, 40)
  172.         txtMines.Text = "15"
  173.         txtMines.TabIndex = 5
  174.         txtMines.Size = New System.Drawing.Size(32, 20)
  175.         txtMines.TextAlign = System.WinForms.HorizontalAlignment.Right
  176.         
  177.         cmdGame.Location = New System.Drawing.Point(8, 8)
  178.         cmdGame.BackColor = System.Drawing.SystemColors.Control
  179.         cmdGame.Size = New System.Drawing.Size(96, 24)
  180.         cmdGame.TabIndex = 1
  181.         cmdGame.Text = "&New Game"
  182.         
  183.         txtRowCount.Location = New System.Drawing.Point(144, 64)
  184.         txtRowCount.Text = "15"
  185.         txtRowCount.TabIndex = 7
  186.         txtRowCount.Size = New System.Drawing.Size(32, 20)
  187.         txtRowCount.TextAlign = System.WinForms.HorizontalAlignment.Right
  188.         
  189.         lblRows.Location = New System.Drawing.Point(104, 72)
  190.         lblRows.Text = "Rows:"
  191.         lblRows.Size = New System.Drawing.Size(40, 16)
  192.         lblRows.TabIndex = 4
  193.         
  194.         lblColumns.Location = New System.Drawing.Point(0, 72)
  195.         lblColumns.Text = "Columns:"
  196.         lblColumns.Size = New System.Drawing.Size(56, 16)
  197.         lblColumns.TabIndex = 3
  198.         
  199.         lblMines.Location = New System.Drawing.Point(0, 40)
  200.         lblMines.Text = "Mines:"
  201.         lblMines.Size = New System.Drawing.Size(56, 16)
  202.         lblMines.TabIndex = 2
  203.         
  204.         '@design ImageList1.SetLocation(New System.Drawing.Point(7, 7))
  205.         ImageList1.ImageSize = New System.Drawing.Size(16, 16)
  206.         ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.WinForms.ImageListStreamer)
  207.         ImageList1.ColorDepth = System.WinForms.ColorDepth.Depth8Bit
  208.         ImageList1.TransparentColor = System.Drawing.Color.Magenta
  209.         
  210.         AxSGGrid1.TabIndex = 0
  211.         AxSGGrid1.Size = New System.Drawing.Size(264, 240)
  212.         AxSGGrid1.OcxState = CType(resources.GetObject("AxSGGrid1.OcxState"), System.WinForms.AxHost.State)
  213.         AxSGGrid1.Location = New System.Drawing.Point(0, 96)
  214.         
  215.         txtColCount.Location = New System.Drawing.Point(56, 64)
  216.         txtColCount.Text = "15"
  217.         txtColCount.TabIndex = 6
  218.         txtColCount.Size = New System.Drawing.Size(32, 20)
  219.         txtColCount.TextAlign = System.WinForms.HorizontalAlignment.Right
  220.         Me.Text = "Form1"
  221.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  222.         Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
  223.         Me.ClientSize = New System.Drawing.Size(292, 349)
  224.         
  225.         Me.Controls.Add(txtRowCount)
  226.         Me.Controls.Add(txtColCount)
  227.         Me.Controls.Add(txtMines)
  228.         Me.Controls.Add(lblRows)
  229.         Me.Controls.Add(lblColumns)
  230.         Me.Controls.Add(lblMines)
  231.         Me.Controls.Add(cmdGame)
  232.         Me.Controls.Add(AxSGGrid1)
  233.         
  234.         AxSGGrid1.EndInit()
  235.     End Sub
  236.     
  237. #End Region
  238.     
  239.     Protected Sub cmdGame_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  240.         AxSGGrid1.Enabled = True
  241.         AxSGGrid1_OnInit(sender, e)
  242.     End Sub
  243.     
  244.     
  245.     Public Sub AxSGGrid1_OnInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxSGGrid1.OnInit
  246.         
  247.         PreInit()
  248.         
  249.         Me.Text = "Minesweeper"
  250.         
  251.         With AxSGGrid1
  252.             .RedrawEnabled = False
  253.             'cols & rows creation
  254.             .DefaultColWidth = SGM_CELL_SIZE
  255.             .DefaultRowHeight = SGM_CELL_SIZE
  256.             .Columns.RemoveAll(True)
  257.             .HeadingRowCount = 0
  258.             .DataRowCount = 0
  259.             .DataColCount = 0
  260.             .DataColCount = mlColCount
  261.             .DataRowCount = mlRowCount
  262.             'disable edit end selection
  263.             .AllowEdit = False
  264.             .SelectionMode = sgSelectionNone
  265.             'grid appearance
  266.             .GroupByBoxVisible = False
  267.             .GridBorderStyle = sgNone
  268.             .CellsBorderVisible = False
  269.             .BackColor = System.Drawing.SystemColors.Control
  270.             .CtlBackColor = System.Drawing.SystemColors.Control
  271.             .FocusRect = sgFocusRectNone
  272.             .GridLines = sgGridLineStyle.sgGridLineNone
  273.             
  274.             vbButtonFace = .GetOleColorFromColor(system.Drawing.SystemColors.Control)
  275.             
  276.             With .Styles("Normal")
  277.                 .Font.Bold = True
  278.                 .TextAlignment = sgAlignCenterCenter
  279.                 .BackColor = vbButtonFace
  280.                 .ForeColor = vbButtonFace
  281.                 .BkgPictureAlignment = sgPicAlignCenterCenter
  282.             End With
  283.             
  284.             With .Styles("Heading")
  285.                 .ForeColor = vbButtonFace
  286.                 .TextAlignment = sgAlignCenterCenter
  287.                 .DisplayType = sgDisplayPicture
  288.                 .BkgPictureAlignment = sgPicAlignCenterCenter
  289.             End With
  290.             
  291.             With .CreateRange(sgRangeFree, _
  292.                0, 0, mlColCount - 1, mlRowCount - 1)
  293.                 .ApplyStyle(AxSGGrid1.Styles("Heading"))
  294.             End With
  295.             
  296.             SetMines()
  297.             
  298.             'resize form
  299.             Me.Width = (mlColCount * SGM_CELL_SIZE) + _
  300.                .Left + (Me.Width - Me.ClientRectangle.Width)
  301.             Me.Height = (mlRowCount * SGM_CELL_SIZE) + _
  302.                .Top + (Me.Height - Me.ClientRectangle.Height())
  303.             
  304.             .Images = ImageList1.Handle
  305.             
  306.             .RedrawEnabled = True
  307.         End With
  308.         
  309.         mdtStartTime = Now
  310.     End Sub
  311.     
  312.     Public Sub AxSGGrid1_MouseUp _
  313.     (ByVal sender As Object, ByVal e As System.WinForms.MouseEventArgs) Handles AxSGGrid1.MouseUp
  314.         Dim cell As Object
  315.         Const vbRed As Integer = 255
  316.         Const vbBlack As Integer = 0
  317.         
  318.         If AxSGGrid1.HitTestObject(e.X, e.Y, cell) <> sgHitCell Then Exit Sub
  319.         
  320.         If e.Button = WinForms.MouseButtons.Left Then
  321.             AxSGGrid1.RedrawEnabled = False
  322.             
  323.             If cell.Value = "M" Then
  324.                 FlatCell(AxSGGrid1.MouseCol, AxSGGrid1.MouseRow)
  325.                 cell.Style.BackColor = vbRed
  326.                 cell.Style.ForeColor = vbBlack
  327.                 ShowAllMines()
  328.                 AxSGGrid1.RedrawEnabled = True
  329.                 AxSGGrid1.Enabled = False
  330.                 MsgBox("Boom!!!", vbExclamation)
  331.                 Exit Sub
  332.             ElseIf cell.Value = "F" Then
  333.                 Exit Sub
  334.             End If
  335.             
  336.             If CInt(cell.Value) = 0 Then
  337.                 cell.Tag = "Open"
  338.                 FlatCell(AxSGGrid1.MouseCol, AxSGGrid1.MouseRow)
  339.                 ShowFreeCells(cell.row.Position, cell.Column.Position)
  340.             Else
  341.                 cell.Tag = "Open"
  342.                 FlatCell(AxSGGrid1.MouseCol, AxSGGrid1.MouseRow)
  343.                 
  344.                 
  345.                 cell.Style.ForeColor = _
  346.                     AxSGGrid1.GetOleColorFromColor(GetCellColor(CInt(cell.Value)))
  347.             End If
  348.             
  349.             AxSGGrid1.RedrawEnabled = True
  350.             
  351.             If CheckGameStatus Then
  352.                 MsgBox("Cool! Your time " & _
  353.                    DateDiff("s", mdtStartTime, Now) & " seconds.", vbInformation)
  354.                 AxSGGrid1.Enabled = False
  355.             End If
  356.             
  357.         ElseIf e.Button = WinForms.MouseButtons.Right Then
  358.             If cell.Tag = Nothing Then
  359.                 cell.Tag = cell.Value
  360.                 cell.Value = "F"
  361.                 cell.Style.BkgPicture = _
  362.                     AxSGGrid1.GetIPictureFromPicture(ImageList1.GetBitmap(enmPictureIds.enmFlag))
  363.             ElseIf cell.Value = "F" Then
  364.                 cell.Value = cell.Tag
  365.                 cell.Style.Reset()
  366.                 cell.Style.ForeColor = vbButtonFace
  367.                 With AxSGGrid1.CreateRange(sgRangeFree, _
  368.                         cell.Column.Position, cell.Row.Position, cell.Column.Position, cell.Row.Position)
  369.                     .ApplyStyle(AxSGGrid1.Styles("Heading"))
  370.                 End With
  371.                 cell.Tag = Nothing
  372.             End If
  373.         End If
  374.         
  375.         AxSGGrid1.Redraw(sgGridRedrawCode.sgRedrawAll)
  376.     End Sub
  377.     
  378.     Private Sub PreInit()
  379.         
  380.         On Error Goto PreInitError
  381.         
  382.         If mlColCount = 0 Or mlRowCount = 0 Or mlMinesCount = 0 Then
  383.             mlColCount = 12
  384.             mlRowCount = 12
  385.             mlMinesCount = 15
  386.         Else
  387.             mlMinesCount = CInt(txtMines.Text)
  388.             mlColCount = CInt(txtColCount.Text)
  389.             mlRowCount = CInt(txtRowCount.Text)
  390.             If mlColCount > MAX_WIDTH Then mlColCount = MAX_WIDTH
  391.             If mlRowCount > MAX_HEIGHT Then mlRowCount = MAX_HEIGHT
  392.             If mlMinesCount < MIN_MINES Then mlMinesCount = MIN_MINES
  393.         End If
  394.         
  395.         txtRowCount.Text = CStr(mlRowCount)
  396.         txtColCount.Text = CStr(mlColCount)
  397.         txtMines.Text = CStr(mlMinesCount)
  398.         
  399.         Exit Sub
  400. PreInitError:
  401.         mlMinesCount = 0
  402.         PreInit()
  403.         Exit Sub
  404.     End Sub
  405.     
  406.     Private Sub SetMines()
  407.         Dim i As Integer, j As Integer
  408.         Dim iMinesCount As Integer
  409.         Dim ar As IsgArray
  410.         Dim lRow As Integer, lCol As Integer
  411.         
  412.         On Error Resume Next
  413.         
  414.         ar = AxSGGrid1.Array
  415.         
  416.         For i = 0 To mlColCount - 1
  417.             For j = 0 To mlRowCount - 1
  418.                 ar(j, i) = 0
  419.             Next
  420.         Next
  421.         
  422.         If mlRowCount * mlColCount < mlMinesCount Then
  423.             MsgBox("Too much mines!!")
  424.             Exit Sub
  425.         End If
  426.         
  427.         Do
  428.             Randomize()
  429.             lRow = CInt(Fix(Rnd * (mlRowCount + 1))) : lCol = CInt(Fix(Rnd * (mlColCount + 1)))
  430.             If lRow <> mlRowCount And lCol <> mlColCount Then
  431.                 If ar(lRow, lCol) <> "M" Then
  432.                     ar(lRow, lCol) = "M"
  433.                     iMinesCount = iMinesCount + 1
  434.                 End If
  435.             End If
  436.         Loop Until (iMinesCount = mlMinesCount)
  437.         
  438.         For i = 0 To mlColCount - 1
  439.             For j = 0 To mlRowCount - 1
  440.                 If ar(j, i) = "M" Then
  441.                     ar(j, i - 1) = CInt(ar(j, i - 1)) + 1
  442.                     ar(j, i + 1) = CInt(ar(j, i + 1)) + 1
  443.                     ar(j - 1, i) = CInt(ar(j - 1, i)) + 1
  444.                     ar(j - 1, i - 1) = CInt(ar(j - 1, i - 1)) + 1
  445.                     ar(j - 1, i + 1) = CInt(ar(j - 1, i + 1)) + 1
  446.                     ar(j + 1, i) = CInt(ar(j + 1, i)) + 1
  447.                     ar(j + 1, i - 1) = CInt(ar(j + 1, i - 1)) + 1
  448.                     ar(j + 1, i + 1) = CInt(ar(j + 1, i + 1)) + 1
  449.                 End If
  450.             Next
  451.         Next
  452.         
  453.         ar = Nothing
  454.     End Sub
  455.     
  456.     Private Function CheckGameStatus() As Boolean
  457.         Dim cell As SGCell, row As SGRow
  458.         
  459.         For Each row In AxSGGrid1.Rows
  460.             For Each cell In row.Cells
  461.                 If cell.Tag = "" And cell.Value <> "F" And cell.Value <> "M" Then
  462.                     Exit Function
  463.                 ElseIf cell.Value = "F" And cell.Tag <> "M" Then
  464.                     Exit Function
  465.                 End If
  466.             Next
  467.         Next
  468.         
  469.         CheckGameStatus = True
  470.     End Function
  471.     
  472.     Private Sub ShowAllMines()
  473.         Dim cell As IsgCell
  474.         Dim row As IsgRow
  475.         Dim hst As AxHost
  476.         
  477.         On Error Goto ShowMinesError
  478.         
  479.         For Each row In AxSGGrid1.Rows
  480.             For Each cell In row.Cells
  481.                 If cell.Value = "M" Then
  482.                     cell.Value = ""
  483.                     
  484.                     cell.Style.BkgPicture = _
  485.                         AxSGGrid1.GetIPictureFromPicture _
  486.                         (ImageList1.Images(enmPictureIds.enmMine))
  487.                 ElseIf cell.Value = "F" Then
  488.                     If cell.Tag = "M" Then
  489.                         cell.Value = ""
  490.                         cell.Style.BkgPicture = _
  491.                             AxSGGrid1.GetIPictureFromPicture _
  492.                             (ImageList1.GetBitmap(enmPictureIds.enmMine))
  493.                     Else
  494.                         cell.Value = ""
  495.                         cell.Style.BkgPicture = _
  496.                             AxSGGrid1.GetIPictureFromPicture _
  497.                             (ImageList1.GetBitmap(enmPictureIds.enmNoMine))
  498.                     End If
  499.                 End If
  500.             Next
  501.         Next
  502.         Exit Sub
  503. ShowMinesError:
  504.         msgbox("error")
  505.         Exit Sub
  506.     End Sub
  507.     
  508.     Private Sub ShowFreeCells(ByVal lRow As Integer, ByVal lCol As Integer)
  509.         Dim cell As IsgCell
  510.         Dim i As Integer
  511.         Dim lColor As Long
  512.         Dim arRows() As Integer = _
  513.             {lRow - 1, lRow - 1, lRow - 1, lRow, _
  514.              lRow, lRow + 1, lRow + 1, lRow + 1}
  515.         Dim arCols() As Integer = _
  516.             {lCol - 1, lCol, lCol + 1, lCol - 1, _
  517.             lCol + 1, lCol - 1, lCol, lCol + 1}
  518.         
  519.         For i = 0 To UBound(arRows)
  520.             If (arRows(i) > -1 And arRows(i) < mlRowCount) _
  521.                And (arCols(i) > -1 And arCols(i) < mlColCount) Then
  522.                 cell = AxSGGrid1.Rows.At(arRows(i)).Cells(arCols(i))
  523.                 If cell.Tag = Nothing Then
  524.                     FlatCell(CInt(arCols(i)), CInt(arRows(i)))
  525.                     cell.Tag = "Open"
  526.                     If CInt(cell.Value) = 0 Then
  527.                         ShowFreeCells(CInt(arRows(i)), CInt(arCols(i)))
  528.                     Else
  529.                         cell.Style.ForeColor = _
  530.                             AxSGGrid1.GetOleColorFromColor(GetCellColor(CInt(cell.Value)))
  531.                     End If
  532.                 End If
  533.             End If
  534.         Next
  535.         cell = Nothing
  536.     End Sub
  537.     
  538.     Private Sub FlatCell(ByVal lCol As Integer, ByVal lRow As Integer)
  539.         With AxSGGrid1.CreateRange(sgRangeFree, _
  540.             lCol, lRow, lCol, lRow)
  541.             .ApplyStyle(AxSGGrid1.Styles("Normal"))
  542.         End With
  543.         
  544.         
  545.     End Sub
  546.     
  547.     Private Sub CenterForm(ByVal frm As Form)
  548.         ' Centers the form on the screen.
  549.         Dim RecForm As rectangle = Screen.GetBounds(frm)
  550.         frm.Left = CInt((RecForm.Width - frm.Width) / 2)
  551.         frm.Top = CInt((RecForm.Height - frm.Height) / 2)
  552.     End Sub
  553.     
  554.     Private Function GetCellColor(ByVal iValue As Integer) As Color
  555.         Select Case iValue
  556.             Case 0
  557.                 Return system.Drawing.SystemColors.Control
  558.             Case 1
  559.                 Return system.Drawing.Color.Blue
  560.             Case 2
  561.                 Return system.Drawing.Color.DarkGreen
  562.             Case 3
  563.                 Return system.Drawing.Color.DarkOrange
  564.             Case 4
  565.                 Return system.Drawing.Color.OliveDrab                
  566.             Case 5
  567.                 Return system.Drawing.Color.Orchid
  568.             Case 6
  569.                 Return system.Drawing.Color.PaleGoldenrod
  570.             Case 7
  571.                 Return system.Drawing.Color.Beige
  572.             Case 8
  573.                 Return system.Drawing.Color.Chocolate
  574.         End Select
  575.     End Function
  576. End Class
  577.