Highlighted
Super Contributor.
Super Contributor.
1731 views

Adding resouces to project

Jump to solution

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?

Phil Levin

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Adding resouces to project

Jump to solution

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.

View solution in original post

0 Likes
3 Replies
Highlighted
Super Contributor.
Super Contributor.

RE: Adding resouces to project

Jump to solution

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.

Phil Levin

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Adding resouces to project

Jump to solution

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.

View solution in original post

0 Likes
Highlighted
Super Contributor.
Super Contributor.

RE: Adding resouces to project

Jump to solution

Thanks.  That was simple.

Phil Levin

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.