jedbartlet Posted September 22, 2004 Posted September 22, 2004 Bear with me if this seems like a basic question cos i'm quite new to c++.net. I've dynamically created an array of picture boxes at runtime, the number of which depends on what value the user enters. I've assigned each box an event handler for when the user clicks on that box. The prolem i'm having is that i can't access any of the properties of the picture box from the event handler. Can anyone help?! Quote
Administrators PlausiblyDamp Posted September 22, 2004 Administrators Posted September 22, 2004 Any chance you could post the relevant code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jedbartlet Posted September 23, 2004 Author Posted September 23, 2004 (edited) void MyForm::InializeComponent(int x) { //All static form properties and components set here .... PictureBox *Gallery[] = new PictureBox *[x]; for(int i =0; i<Gallery->Length; i++) { Gallery = new PictureBox; Gallery->BorderStyle = BorderStyle::Fixed3D; // more properties set here.... Gallery->Click += new EventHandler(this, pbox_Click); } } void MyForm:: pbox_Click(Object *sender, EventArgs *e) { Gallery[2]->Size = Drawing::Size(100,100); //other stuff } Thats the gist of it. I get an undeclared identifier "Gallery" in the debug window which occurs on the gallery[2]->Size.... line in the event handler. I thought the problem was that when i assign the event handler i'm using the this pointer instead of a pointer to gallery but i can't get it to accept Gallery[] or *Gallery[] or anything similar. I think i'm missing something obvious but the more i stare at it the more confused i get! Edited September 23, 2004 by jedbartlet Quote
Administrators PlausiblyDamp Posted September 23, 2004 Administrators Posted September 23, 2004 You have declared the array inside the InitializeComponent routine - therefore it is only visible in that routine. If it needs to be accessed from several procedures then move the PictureBox *Gallery[]; bit to the form itself. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.