|
-
Nov 6th, 2006, 04:33 PM
#1
Thread Starter
Junior Member
[02/03] Adding a picturebox to the main form from code.
Hey all,
I'm recreating an old board game on the computer using VB. This game has player tokens that have to be displayed on the screen. I used the "Component" class to create the definition of a player, from which I instantiate a player for each player that is playing. Within the class, I define a picturebox with an image inside to represent the player token.
Here's the problem - I can't get the token pictureboxes to appear on the screen. I am almost positive that it is because I am not putting them in a container. I tried to pass the form as a container to put the tokens on, but it errors out when I try to do that, saying it is an invalid cast. Here is the code for a new Player:
VB Code:
Public Sub New(ByVal Container As System.ComponentModel.IContainer, ByVal tempCash As Integer, ByVal tempPlaying As Integer, ByVal tempColor As String)
MyClass.New(tempCash, tempPlaying, tempColor)
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub
Public Sub New(ByVal tempCash As Integer, ByVal tempPlaying As Integer, ByVal tempColor As String)
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
cash = tempCash
colorName = tempColor
playing = tempPlaying
If tempColor = "Red" Then
token.Image() = System.Drawing.Bitmap.FromFile("redpiece.png")
color = System.Drawing.Color.FromArgb(255, 128, 128)
ElseIf tempColor = "Blue" Then
token.Image() = System.Drawing.Bitmap.FromFile("bluepiece.png")
color = System.Drawing.Color.FromArgb(128, 128, 255)
ElseIf tempColor = "Green" Then
token.Image() = System.Drawing.Bitmap.FromFile("greenpiece.png")
color = System.Drawing.Color.FromArgb(128, 255, 128)
ElseIf tempColor = "Yellow" Then
token.Image() = System.Drawing.Bitmap.FromFile("yellowpiece.png")
color = System.Drawing.Color.FromArgb(255, 255, 128)
ElseIf tempColor = "Black" Then
token.Image() = System.Drawing.Bitmap.FromFile("blackpiece.png")
color = System.Drawing.Color.Gray
ElseIf tempColor = "White" Then
token.Image() = System.Drawing.Bitmap.FromFile("whitepiece.png")
color = System.Drawing.Color.White
Else
System.Console.WriteLine("Error in New() in Player.vb while trying to assign a color to the token")
End If
If playing = 1 Or playing = 2 Then
token.Visible = True
token.Location = spacesArray(0).getLocation
End If
End Sub
My error message ("Error in New()...") doesn't come up in the console, so it is assigning a picture to the token, and playing always = 1 at this point (eventually 0 will be not playing, 1 will be a human playing, and 2 will be a CPU playing). Any suggestions? Should I create a container on the form (like a panel) that is transparent and use that for the token positions?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|