CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2010
    Posts
    29

    Image not being displayed

    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

  2. #2
    Join Date
    Feb 2010
    Posts
    29

    Re: Image not being displayed

    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

  3. #3
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Image not being displayed

    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;
    }
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  4. #4
    Join Date
    Feb 2010
    Posts
    29

    Re: Image not being displayed

    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

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Image not being displayed

    this is still not enough and if you don't want us to guess post the whole code.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #6
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Image not being displayed

    Is the new Form is getting created in the original parent thread or in the new thread you are calling ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured