Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
GeneralRe: String to Object Instance Problem Pin
Pete O'Hanlon17-Jul-12 3:50
mvePete O'Hanlon17-Jul-12 3:50 
GeneralRe: String to Object Instance Problem Pin
atoi_powered17-Jul-12 3:57
atoi_powered17-Jul-12 3:57 
GeneralRe: String to Object Instance Problem Pin
Pete O'Hanlon17-Jul-12 4:19
mvePete O'Hanlon17-Jul-12 4:19 
GeneralRe: String to Object Instance Problem Pin
atoi_powered17-Jul-12 4:21
atoi_powered17-Jul-12 4:21 
GeneralRe: String to Object Instance Problem Pin
Pete O'Hanlon17-Jul-12 4:25
mvePete O'Hanlon17-Jul-12 4:25 
GeneralRe: String to Object Instance Problem Pin
BobJanova17-Jul-12 3:58
BobJanova17-Jul-12 3:58 
GeneralRe: String to Object Instance Problem Pin
Pete O'Hanlon17-Jul-12 4:17
mvePete O'Hanlon17-Jul-12 4:17 
AnswerRe: String to Object Instance Problem Pin
BobJanova17-Jul-12 3:58
BobJanova17-Jul-12 3:58 
Okay, I've read this whole thread and you're horribly confused about classes and instances. Your user name indicates you come from non-class-based procedural languages, and perhaps you need to keep the Object Oriented chapter of your C# book open while you learn!

The failed code that you are trying here is trying to find a type, and create a new instance of that type. Activator.CreateInstance(sometype) is logically equivalent to new sometype(), and in fact the snippet you posted can be written exactly as
PictureBox picture = new pictureBox99.BackgroundImage();
picture.BackgroundImage = Resource1.island;

Hopefully you can see why that doesn't work!

You are not trying to create a copy of something whose final type is not known at compile time, which is about the only time I've needed to use reflection based instantiation. No, what you want to do is find all the instances and do the same thing to them:

foreach(Control c in Controls){
 PictureBox picture = c as PictureBox;
 if(picture != null)
  picture.BackgroundImage = Resource1.island;
}


or with Linq:

this.Controls.Select(c => c as PictureBox).Where(c => c != null).ToList().ForEach(pb => pb.BackgroundImage = Resource1.island);


(the ToList being necessary because ForEach isn't defined except on Lists).
GeneralRe: String to Object Instance Problem Pin
atoi_powered17-Jul-12 4:09
atoi_powered17-Jul-12 4:09 
GeneralRe: String to Object Instance Problem Pin
BobJanova18-Jul-12 2:33
BobJanova18-Jul-12 2:33 
GeneralRe: String to Object Instance Problem Pin
atoi_powered18-Jul-12 3:11
atoi_powered18-Jul-12 3:11 
QuestionBetter date / time parse? Pin
SledgeHammer0116-Jul-12 12:50
SledgeHammer0116-Jul-12 12:50 
AnswerRe: Better date / time parse? Pin
Peter_in_278016-Jul-12 14:01
professionalPeter_in_278016-Jul-12 14:01 
AnswerRe: Better date / time parse? Pin
BobJanova17-Jul-12 0:14
BobJanova17-Jul-12 0:14 
QuestionRepresenting a 4 digit integer in 2 positions alphanumeric placeholder. Pin
RK KL16-Jul-12 8:23
RK KL16-Jul-12 8:23 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
OriginalGriff16-Jul-12 8:38
mveOriginalGriff16-Jul-12 8:38 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
RK KL16-Jul-12 8:46
RK KL16-Jul-12 8:46 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
PIEBALDconsult16-Jul-12 9:27
mvePIEBALDconsult16-Jul-12 9:27 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
Ian Shlasko16-Jul-12 9:41
Ian Shlasko16-Jul-12 9:41 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
harold aptroot16-Jul-12 8:52
harold aptroot16-Jul-12 8:52 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
OriginalGriff16-Jul-12 9:40
mveOriginalGriff16-Jul-12 9:40 
AnswerRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
Big Daddy Farang16-Jul-12 8:40
Big Daddy Farang16-Jul-12 8:40 
AnswerRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
RK KL16-Jul-12 9:08
RK KL16-Jul-12 9:08 
AnswerRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
PIEBALDconsult16-Jul-12 9:41
mvePIEBALDconsult16-Jul-12 9:41 
GeneralRe: Representing a 4 digit integer in 2 positions alphanumeric placeholder. Pin
Paul Conrad16-Jul-12 10:52
professionalPaul Conrad16-Jul-12 10:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.