martin2k

ForumsVB6GamesSoftwareDirectoryHTMLArticlesBlogContact

I am trying to create a simulated chess board.


 

Home

Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here

Contact


 

Question

From: Keith Reed
Date: Saturday 30 May 2009 7:16 AM
Subject: RE: vb6 tips
Question: I am trying to create a simulated chess board.(Alternate black/white squares)

I have written some code, which you will hopefully find useful.  All you need is a PictureBox called picBoard, with the Left and Top properties set to 0.  Then add this code:

Private Sub Form_Resize()
Dim i As Integer, j As Integer, blck As Boolean, x As Single, y As Single, c As Long, x2 As Single, y2 As Single

picBoard.Width = ScaleWidth
picBoard.Height = ScaleHeight
picBoard.Picture = LoadPicture("")

x2 = picBoard.ScaleWidth / 8
y2 = picBoard.ScaleHeight / 8

For i = 1 To 8
    For j = 1 To 8
        blck = Not blck

        If blck = True Then
            c = vbBlack
        Else
            c = vbWhite
        End If

        picBoard.Line (x, y)-(x + x2, y + y2), c, BF

        y = y2 * j
    Next j

    blck = Not blck
    x = x2 * i
    y = 0
Next i
End Sub


blog comments powered by Disqus
Martin Allen 1999 - 2011.  Last updated Saturday 13 August 2011 12:07:02 AM +0100.