CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Posts
    3

    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
    6,620

    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
    3

    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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Updating the image on a botton

    This is the Visual c++ forum.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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