-
August 2nd, 2013, 07:35 PM
#1
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
-
August 4th, 2013, 09:46 AM
#2
Re: Updating the image on a botton
Originally Posted by alirezan1
Any ideas?
Wrong forum.
Best regards,
Igor
-
August 6th, 2013, 01:04 PM
#3
Re: Updating the image on a botton
Originally Posted by Igor Vartanov
Wrong forum.
How is this the wrong forum!?
-
August 6th, 2013, 01:13 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|