Hello.
This is my code, im new to classes and im trying to make a class that can make easier to create a new "player" to my game using objects.
Previously to this, i had to call a function to create the player and a lot of stuff came whit that.
Now i can just declare
Player1 as new (Class name)
and modify it like Player1.name = (value)
..
yeah,
so my issue is that when im trying to assign the picturebox (which is created to link the player propieties to it), to the pubolic variable cImage (Which contains the image file path), it doesnt seem to work.
This is the code section.
Public Property Image As Image
Get
Return cImage
End Get
Set(ByVal value As Image)
cImage = value
personajeobject.Image = cImage
End Set
End Property
This is the full class
Imports System.Drawing
Public Class Personaje
Public cName As String
Public cWidth As Integer
Public cHeight As Integer
Public cImage As Image
Public cX As Integer
Public cY As Integer
Public cVisible As Boolean
Public personajeobject As PictureBox
Public Property Name As String
Get
Return cName
End Get
Set(ByVal value As String)
cName = value
personajeobject.Name = cName
End Set
End Property
Public Property X As Integer
Get
Return cX
End Get
Set(ByVal value As Integer)
cX = value
personajeobject.Location = New Point(cX, cY)
End Set
End Property
Public Property Y As Integer
Get
Return cY
End Get
Set(ByVal value As Integer)
cY = value
personajeobject.Location = New Point(cX, cY)
End Set
End Property
Public Property Width As String
Get
Return cWidth
End Get
Set(ByVal value As String)
cWidth = value
personajeobject.Width = cWidth
End Set
End Property
Public Property Height As String
Get
Return cHeight
End Get
Set(ByVal value As String)
cHeight = value
personajeobject.Height = cHeight
End Set
End Property
Public Property Image As Image
Get
Return cImage
End Get
Set(ByVal value As Image)
cImage = value
personajeobject.Image = cImage
End Set
End Property
Public Property Visible As Boolean
Get
Return cVisible
End Get
Set(ByVal value As Boolean)
cVisible = value
personajeobject.Visible = cVisible
End Set
End Property
Public Function CrearPersonaje(ByVal formname As Form, ByVal Name As String, ByVal Width As Integer, ByVal height As Integer, ByVal Image As System.Drawing.Image, ByVal x As Integer, ByVal y As Integer, ByVal visible As Boolean)
cName = Name
cWidth = Width
cHeight = height
cImage = Image
cX = x
cY = y
cVisible = visible
personajeobject = New PictureBox
personajeobject.Image = cImage
formname.Controls.Add(personajeobject)
Return 0
End Function
End Class
This is form load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
arquimedes.CrearPersonaje(Me, "Arquimedes", 50, 80, Image.FromFile(Application.StartupPath & "\pl1.png"), 100, 100, True)
MsgBox(arquimedes.Width)
End Sub
Thank you all.