martin2k

Google
 
Web www.martin2k.co.uk

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


Please fill in the below form if you have any comments or additional information you want to add about the above information.  If you have any Visual Basic 6.0 questions, please visit the Forum.

PLEASE NOTE: Questions sent via this form cannot be answered.  Please ask questions at the Forum.

* - Mandatory

*Name: E-mail:

*Comments:

*Please type the following code (your comment will not be accepted without it):

PLEASE NOTE: Questions sent via this form cannot be answered.  Please ask questions at the Forum.


Martin Allen 1999 - 2009.  Last updated Tuesday 02 June 2009 09:26:46 PM +0100.