Here ... add Picture1 to a form. Inside that, place another picture box and
name it pixboard, and set its index to 0 to create a control array. Add
Command1 and run.
Option Explicit
Private Type ControlLayoutData
totalRows As Long
totalColumns As Long
rowPadding As Long
colPadding As Long
ctlHeight As Long
ctlWidth As Long
platemapTop As Integer
platemapLeft As Integer
boardcolor1 As Long
boardcolor2 As Long
boardbackcolor As Long
End Type
Private Sub Command1_Click()
Dim cld As ControlLayoutData
With cld
.colPadding = 0
.rowPadding = 0
.ctlHeight = 915
.ctlWidth = 915
.platemapTop = 400
.platemapLeft = 400
.totalRows = 8
.totalColumns = 8
.boardbackcolor = &H363559
.boardcolor1 = &HB6A029
.boardcolor2 = &HF3FFE8
End With
Picture1.Visible = False
Call CreateBoard(cld, False)
Picture1.Visible = True
End Sub
Private Sub CreateBoard(cld As ControlLayoutData, _
InvertBoard As Boolean)
Dim cnt As Long
Dim nCol As Long
Dim nRow As Long
Dim pixTop As Long
Dim pixLeft As Long
pixTop = Picture1.Top
pixLeft = Picture1.Left
Picture1.BackColor = cld.boardbackcolor
'Preload all the required controls.
'VB's default state is hidden. Since
'controls are cloned, set the
'initial control's height and width,
'avoiding the need to set it in the
'loop below.
With pixboard(0)
.Height = cld.ctlHeight
.Width = cld.ctlWidth
.BorderStyle = 0
End With
'load the bunch
For cnt = 1 To (cld.totalRows * cld.totalColumns)
Load pixboard(cnt)
Next
cnt = 0
'now position the controls to form
'a grid sized as specified
For nRow = 1 To cld.totalRows
For nCol = 1 To cld.totalColumns
'position and show each
'square
With pixboard(cnt)
.Top = cld.platemapTop + _
((cld.ctlHeight * nRow) - cld.ctlHeight) + _
(cld.rowPadding * (nRow - 1))
.Left = cld.platemapLeft + _
((cld.ctlWidth * nCol) - cld.ctlWidth) + _
(cld.colPadding * (nCol - 1))
'switch colours every second
'square. When abs(invertboard)
'equals 0, Black is at the top.
'when it equals 1, Black is at
'the bottom
If ((nRow + nCol) Mod 2 = Abs(InvertBoard)) Then
.BackColor = cld.boardcolor1
Else
.BackColor = cld.boardcolor2
End If
.Visible = True
End With
cnt = cnt + 1
Next nCol
Next
'size the main picture to reveal
'all the controls
With Picture1
.Width = (cld.ctlWidth * cld.totalColumns) + _
(cld.colPadding * (cld.totalColumns - 1)) + _
((cld.platemapLeft) * 2)
.Height = (cld.ctlHeight * cld.totalRows) + _
(cld.rowPadding * (cld.totalRows - 1)) + _
((cld.platemapTop) * 2)
End With
'resize the form to accomodate the pixbox
'with a bit of margin
With Form1
.Move .Left, .Top, _
Picture1.Width + Picture1.Left + 400, _
Picture1.Height + 800 + Picture1.Top
End With
End Sub
--
Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Fuddzy" <EMAIL REMOVED> wrote in message
news:3fc7cf7a$EMAIL REMOVED...
: Bob wrote:
: <> If you elaborate on what you are trying to do it might help>>
:
: Hi Bob........... here is part of the scenerio
:
: Suppose I want to create a mosaic (similiar to a chessboard) and I would
use
: a picturebox array of approx 100 controls all built under prg control.
While
: my loops are building the control array of pictureboxes......... I want to
: provide a background color to each.............. thus that part of the
code
: (If there was such an "IN" operator or function in VB6) would look
something
: like,.........
:
: If someRow% IN(2,6,9,12) and someIndex% IN(9, 17, 25, 34) then
: myPicturebox(someIndex).BackColor = someColor
: else
: myPicturebox(someIndex).BackColor = someOtherColor
: end if
:
: I know I could use a Case Select, but that would take more code than ( the
: IN opereator as used in databases)...... so my question still remains as:
: What Function or Operator does VB provide for a similar result ??
:
: Thanks
: Fud
:
: "Bob Butler" <EMAIL REMOVED> wrote in message
: news:EMAIL REMOVED m...
: > "Fuddzy" <EMAIL REMOVED> wrote in message
: news:<3fc3b0f3$EMAIL REMOVED>...
: > > Hello
: > >
: > > What is the comparable function in Vb6 to the IN function used in
: databases.
: > > Would it be Switch ??
: >
: > possibly a select case...
: >
: > select case thevalue
: > case "choice1","choice2","choice3":
: > ' code for those 3
: > case "choice4","choice5":
: > ' code for those 2
: > case else:
: > ' catch remaining
: > end select
: >
: > If you elaborate on what you are trying to do it might help
:
: