Click to See Complete Forum and Search --> : Image not being displayed
bassguru
February 24th, 2010, 09:35 AM
Hello everyone,
The problem with the code below is that pictureBox2 is not displaying the image.
public static void updateImage()
{
Image img;
Form1 myClass = new Form1();
img = myClass.pictureBox1.Image;
myClass.pictureBox2.Image = img;
}
My guess is that it is because I have to create a new instance of the Form1 class. Any suggestions?
Many thanks in advance,
bassguru
bassguru
February 24th, 2010, 09:40 AM
A more efficient version of that code is:
public static void updateImage()
{
Form1 myClass = new Form1();
myClass.pictureBox2.Image = myClass.pictureBox1.Image;
}
Same problem still exists I'm afraid.
Bassguru
memeloo
February 24th, 2010, 11:47 AM
that's not enough code to tell you what to do... I'll be guessing:
public static void updateImage()
{
this.pictureBox2.Image = this.pictureBox1.Image;
}
bassguru
February 24th, 2010, 11:55 AM
Thanks for the reply memeloo,
However, I get the following error message:
"Keyword 'this' is not valid in a static property, static method, or static field initializer"
Essentially, I am attempting to copy one image and display it in a second pictureBox. What method would be most appropriate for this, as I do not believe it can be done in a 'public static void' method.
I am calling this method by doing the following:
protected static void Connect()
{
Thread newThread = new Thread(new ThreadStart(updateImage));
newThread.Start();}
Many thanks,
bassguru
memeloo
February 24th, 2010, 12:04 PM
this is still not enough and if you don't want us to guess post the whole code.
vcdebugger
February 25th, 2010, 06:10 AM
Is the new Form is getting created in the original parent thread or in the new thread you are calling ?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.