7 Replies - 339 Views - Last Post: 07 February 2013 - 12:53 PM Rate Topic: -----

#1 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Image as property in class

Posted 06 February 2013 - 03:06 PM

Hello,

I am trying to set up an image as a property of my "Player" class, just so i can modify any new "Player" i create by its properties.


This is kinda the code im using

imports system.drawing
private mImage as Image 

public property Image as Image
 get
  return mImage
 end get
 set (value as Image)
  mImage = value
Playerob.image = mImage 'Player ob is declared as picturebox somewhere else.

 end set
end property



Im asigning the variables 'linking' them to a new picturebox. Ex: Playerob.name = mName, Playerob.image = mImage... So any change that is make to the property modifies the picturebox itself.

Every single one of the properties but image works well whit this method im using. that means i can put
"Player1.Width = 20" and it works like a charm. But i cant modify the image and it doesnt even appear if i dont put this line of code
Playerob.image = mImage 'Player ob is declared as picturebox somewhere else.


Into the function that creates the player.

Thank you all

Is This A Good Question/Topic? 0
  • +

Replies To: Image as property in class

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,540
  • Joined: 12-December 12

Re: Image as property in class

Posted 06 February 2013 - 04:04 PM

The first thing I would do would be to change this:

public property Image as Image

[Why do people do this, ugh!? Sorry, having a little moan :) ]
Was This Post Helpful? 0
  • +
  • -

#3 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Image as property in class

Posted 06 February 2013 - 07:22 PM

It isnt actually like that, i was trying to show an example of my code.

Thank you.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: Image as property in class

Posted 07 February 2013 - 10:11 AM

View Postandrewsw, on 07 February 2013 - 12:04 AM, said:

The first thing I would do would be to change this:

public property Image as Image

[Why do people do this, ugh!? Sorry, having a little moan :)/>/>/> ]


Because it's perfectly legal to do so in vb.net. public property Image As Image

vb.net recognized the first Image as the property name and the second Image as the type.

This also the reason you can use Keywords as identifiers as long as you surround it with square braces [ ]

This post has been edited by AdamSpeight2008: 07 February 2013 - 10:12 AM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,540
  • Joined: 12-December 12

Re: Image as property in class

Posted 07 February 2013 - 10:17 AM

@Adam I didn't say it wasn't legal, but I, personally, don't consider it sensible.

@OP What error messages do you receive? If none, then do you know how to debug/step-through the code?
Was This Post Helpful? 0
  • +
  • -

#6 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Image as property in class

Posted 07 February 2013 - 10:27 AM

Great but, does anybody know why my code isnt working as it should?
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1029
  • View blog
  • Posts: 4,007
  • Joined: 02-July 08

Re: Image as property in class

Posted 07 February 2013 - 11:00 AM

Maybe the problem is how and where you set the property not inside of this property. The other thing I don't understand is I want to set a property with a property thing. Seems redundant to me.
Was This Post Helpful? 0
  • +
  • -

#8 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Image as property in class

Posted 07 February 2013 - 12:53 PM

Self Fixed
That last sentence pretty much solved my problem.
I was using variables that i didnt even need to be using.
How stupid of me.

Thank you anyways.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1