Updating the image on a botton
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Updating the image on a botton

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Updating the image on a botton

    Hi

    I have created an application that has bunch of buttons on top and i want to change the image when I click on the button. But unfortunately I can't get it to work.

    Here is the code:

    if (serialPort1.IsOpen)
    {
    tsbCommPortOpenClose.ToolTipText = "Open serial port";
    closeCommPortToolStripMenuItem.Text = "Open serial port";
    tsbCommPortOpenClose.Image = Image.FromFile("Red.bmp");
    serialPort1.Close();
    }
    else
    {
    tsbCommPortOpenClose.ToolTipText = "Close serial port";
    closeCommPortToolStripMenuItem.Text = "Close serial port";
    tsbCommPortOpenClose.Image = image2;
    openComPort(true);
    }

    The second one which changes the image to "image2" works fine. Here is the definition of image2:
    namespace Regress;
    ...
    private Bitmap image2;
    System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
    StreammyStream = myAssembly.GetManifestResourceStream("Regress.Sharing.gif");
    image2 = new Bitmap(myStream);


    When I do the same with the other image that I want to use, it won't work! I opened the project properties and added the image into the resources too, and it still doesn't work.
    It fails and says the file was not there. I've put a copy of the file in the root directory and one in "Resources" folder but it still doesn't work.

    Any ideas?

    Thanks

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: Updating the image on a botton

    Quote Originally Posted by alirezan1 View Post
    Any ideas?
    Wrong forum.
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2012
    Posts
    2

    Re: Updating the image on a botton

    Quote Originally Posted by Igor Vartanov View Post
    Wrong forum.
    How is this the wrong forum!?

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,335

    Re: Updating the image on a botton

    This is the Visual c++ forum.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center