[Gambas-user] How to use events with an object in object[]?

Leonardo Miliani leonardo at ...1237...
Sat Dec 29 16:40:36 CET 2007


I'm writing a little program (a game using a chessboard and some pawns)
and I would like to use a collection of PictureBoxes inside an Object[].
This is my code:

PRIVATE BlackPawns AS NEW Object[]
PRIVATE WithePawns AS NEW Object[]
PRIVATE BlackPawn AS PictureBox
PRIVATE WhitePawn AS PictureBox

PUBLIC SUB _new()
DIM varI AS Integer
DIM varX AS Integer

  varX = 48
  FOR varI = 0 TO 2
    BlackPawn = NEW PictureBox(ME)
    BlackPawn = picture.Load(Application.Path & "/graphics/blackpawn.png")
    BlackPawn.BackColor = IIf((varI MOD 2) = 0, &h000000, &hffffff)
    BlackPawn.Name = "BlackPawn" & Trim(CStr(varI))
    BlackPawn.X = varX
    BlackPawn.Y = 72
    WhitePawn = NEW PictureBox(ME)
    WhitePawn.Picture = picture.Load(Application.Path &
"/graphics/whitepawn.png")
    WhitePawn.BackColor = IIf((varI MOD 2) = 0, &h000000, &hffffff)
    WhitePawn.Name = "WhitePawn" & Trim(CStr(varI))
    WhitePawn.X = varX
    WhitePawn.Y = 172

    BlackPawns.Add(BlackPawn)
    WhitePawns.Add(WhitePawn)
    varX = varX + 50
  NEXT
END

The pictureboxes are created, put inside the array Object[] and showed
on the chessboard. Now I would like to manage the MouseDown event to
change the picture of the selected pawn to show a different one that
should mean I selected it.

But I cannot manage them using the normal event methods...
I mean that if I write a piece of code like this:

PUBLIC SUB WhitePawns_MouseDown()

  LAST.picture = picture.Load(Application.Path &
"/graphics/whitepawn_sel.png")

END

It doesn't do anything...

-- 
Ciao.
Leo.

Web: www.leonardomiliani.com
E-mail: leonardo at ...1237...
Scegli software opensource - Choose opensource software





More information about the User mailing list