Skip to main content

I have several .jpg files that I would like to add as resources.  I use these to display a variable background color for a control at run time.  I have not found a way to add them under Properties..Resources so I tried adding them in my program code but have not been successful at doing this.  Any examples on how to do this?


#VisualCOBOL

I have several .jpg files that I would like to add as resources.  I use these to display a variable background color for a control at run time.  I have not found a way to add them under Properties..Resources so I tried adding them in my program code but have not been successful at doing this.  Any examples on how to do this?


#VisualCOBOL

This is my code:

            declare img as type System.Drawing.Image

            set img to type System.Drawing.Image::FromFile("S:\\V60\\AWMGD\\AG_100_EnterTrans\\AG_100_MaintTrans\\Resources\\Checks.jpg")

            declare rsxw as type System.Resources.ResXResourceWriter

            set rsxw to new type System.Resources.ResXResourceWriter("frmMaintTrans.resources.resX")

            invoke rsxw::AddResource("Checks", img)

            invoke rsxw::Generate()

            invoke rsxw::Close()

            DECLARE rm  as type System.Resources.ResourceManager

            SET rm to new type System.Resources.ResourceManager("AG_100_MaintTrans.frmMaintTrans", type System.Reflection.Assembly::GetExecutingAssembly())

            DECLARE anObject as type Object

            SET anObject to rm::GetObject("Checks")

GetObject always returns null.

As a workaround, when I create the form I create separate Image variables for each .jpg file, in working storage.


I have several .jpg files that I would like to add as resources.  I use these to display a variable background color for a control at run time.  I have not found a way to add them under Properties..Resources so I tried adding them in my program code but have not been successful at doing this.  Any examples on how to do this?


#VisualCOBOL

I do not have a problem with adding a jpg file to a resource file and accessing this within a WinForm program.

Right-click on project and select Add-->New Item and select Assembly Resource file.

This will add the files resource1.resx and resource1.Designer.resx to the project.

Double-click resource1.resx to open in Resource editor.

Click on drop-down arrow next to Add Resource and Select Add Existing File and then navigate to your jpg files and add them. In my case I added vcproduct.jpg.

Save this.

I can then populate a PictureBox control and a button background with the .jpg using syntax:

          set pictureBox1::Image to type testresource.Resource1::vcproduct

          set button1::BackgroundImage to type testresource.Resource1::vcproduct

Where testresource is the name of my project and therefore the default namespace.

Thanks.


I have several .jpg files that I would like to add as resources.  I use these to display a variable background color for a control at run time.  I have not found a way to add them under Properties..Resources so I tried adding them in my program code but have not been successful at doing this.  Any examples on how to do this?


#VisualCOBOL

Thanks.  That was simple.