i-Thomas
asked on
Deployment / Resources
Hi Experts!
I have written my first C# app that includes a number of background images, button images and avi movies.
Right now I read images and movies from a folder structure on disk.
The disadvantage is that everybody can simply exchange or manipulate these images.
Is it possible to included all the resources into a binary resource file and access them from there? What do I have to rearrange in my project to do it?
The next question:
I would like to deploy the app in such a way that .NET framework is included in the installation. How to do this?
I need some practical step-by-step advise how to handle this installer building, so-to-speak some condensed info for beginners. There are endless complicated articles on the web. I need to get started hands-on and all the C# books I have also do not comment on deploying my first application...
Thank you very much in advance for helping!
I have written my first C# app that includes a number of background images, button images and avi movies.
Right now I read images and movies from a folder structure on disk.
The disadvantage is that everybody can simply exchange or manipulate these images.
Is it possible to included all the resources into a binary resource file and access them from there? What do I have to rearrange in my project to do it?
The next question:
I would like to deploy the app in such a way that .NET framework is included in the installation. How to do this?
I need some practical step-by-step advise how to handle this installer building, so-to-speak some condensed info for beginners. There are endless complicated articles on the web. I need to get started hands-on and all the C# books I have also do not comment on deploying my first application...
Thank you very much in advance for helping!
ASKER
1) How to use ImageList control for this purpose? Please post some code example
2) Does it work also for the avis? I guess not...
3) I read something on the web that if .NET SDK is installed and .NET Bootstrap... (whatever this is) then you can create installation package with .NET redistributable package included. Do you know how this works? This should be basic problem of 1000s of developers...
Thanks a lot for your quick reaction!
2) Does it work also for the avis? I guess not...
3) I read something on the web that if .NET SDK is installed and .NET Bootstrap... (whatever this is) then you can create installation package with .NET redistributable package included. Do you know how this works? This should be basic problem of 1000s of developers...
Thanks a lot for your quick reaction!
1. You can use ImageList control very simple: drag ImageList control to your form, then open Property bag, select Images property, then add many images as you want. For example, I have a tree view control and want to apply image for node, in design mode, select TreeView control and bring up Property Bag, select ImageList property then select the ImageList control you just created.
TreeView.SelectedImageInde x property: select the image available from the list
TreeView.ImageIndex property: select the image available from the list
TreeNode node = new TreeNode();
node.Text = "Something";
node.ImageIndex = intIndexFromList;
node.SelectedImageIndex = intIndexFromList;
TreeView.Nodes.Add(node);
TreeView.SelectedImageInde
TreeView.ImageIndex property: select the image available from the list
TreeNode node = new TreeNode();
node.Text = "Something";
node.ImageIndex = intIndexFromList;
node.SelectedImageIndex = intIndexFromList;
TreeView.Nodes.Add(node);
2) For avi, I think you right, it is impossible to do that
3) You can get dotnetfx.exe from www.asp.net. Its size about 20Mb. In your installation, force user to install dotnetfx first
3) You can get dotnetfx.exe from www.asp.net. Its size about 20Mb. In your installation, force user to install dotnetfx first
Build a resouce only assembly and load your images and files from it at runtime.
Here is the article hoe to do it..
http://www.funducode.com/csharpart/csarticle19.htm
jatinder
Here is the article hoe to do it..
http://www.funducode.com/csharpart/csarticle19.htm
jatinder
ASKER
Thanks so far for the additional hints.
I will work through them today and give you feedback!
I will work through them today and give you feedback!
ASKER
Now I come back to you, unfortunately only now and time is running out.
@jatinderalagh
This article is interesting, but I would prefer to directly build the images into my code, not in a separate resource file.
I have found another article here at ee about this:
https://www.experts-exchange.com/questions/20769673/How-to-get-the-current-directory-for-generic-loading-images.html
I took the solution of the accepted answer. My code:
public Form1()
{
InitializeComponent();
Stream pStream = this.GetType().Assembly.Ge tManifestR esourceStr eam("Bitma p1.bmp");
Image pImage = Image.FromStream(pStream, false, true);
uxImagePbx.Image = pImage;
pStream.Close();
}
I tried two ways of adding a bitmap to my project:
1) drag and drop image from Windows Explorer to my project references
2) Use "Add Item" after right mouse click on it and then select the bitmap (allows only .bmp!?)
It resides in the same level hierarchy as the Form1.cs file.
Unfortunately I get the following error message described in another article at ee:
https://www.experts-exchange.com/questions/21088244/cant-get-bitmap-to-be-used-as-embedded-resource-code-supplied.html
An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.
The problem is:
I do not know why, because I set the property of the bitmap to "embedded resource" and did not forget it as describes in this article.
Perhaps I have to set some special compiler settings or make other settings in the IDE?
I hope you can help me, I have to finish the project till Sunday evening!
Thank you very much for helping!
@jatinderalagh
This article is interesting, but I would prefer to directly build the images into my code, not in a separate resource file.
I have found another article here at ee about this:
https://www.experts-exchange.com/questions/20769673/How-to-get-the-current-directory-for-generic-loading-images.html
I took the solution of the accepted answer. My code:
public Form1()
{
InitializeComponent();
Stream pStream = this.GetType().Assembly.Ge
Image pImage = Image.FromStream(pStream, false, true);
uxImagePbx.Image = pImage;
pStream.Close();
}
I tried two ways of adding a bitmap to my project:
1) drag and drop image from Windows Explorer to my project references
2) Use "Add Item" after right mouse click on it and then select the bitmap (allows only .bmp!?)
It resides in the same level hierarchy as the Form1.cs file.
Unfortunately I get the following error message described in another article at ee:
https://www.experts-exchange.com/questions/21088244/cant-get-bitmap-to-be-used-as-embedded-resource-code-supplied.html
An unhandled exception of type 'System.ArgumentException'
Additional information: 'null' is not a valid value for 'stream'.
The problem is:
I do not know why, because I set the property of the bitmap to "embedded resource" and did not forget it as describes in this article.
Perhaps I have to set some special compiler settings or make other settings in the IDE?
I hope you can help me, I have to finish the project till Sunday evening!
Thank you very much for helping!
You can build a resource file. And add it to the same application this way your resources will be embedded in same assembly. Then you will be able to use the ResourceManger class for reding the resouces.
For creating the resource file : -
The .NET Framework includes a sample application called ResEditor that facilitates creating and editing resource files. The ResEditor application allows you to create binary resource files (.resources) as well as XML resource files (.resX).
Building ResEditor
ResEditor is provided as source code with the .NET Framework SDK. Before you can use ResEditor, you must build it using the supplied batch file.
To build the ResEditor Application
1. Start Windows, and then click the Start button, point to All Programs, then Visual Studio .NET 2003, then Visual Studio .NET Tools, then Visual Studio .NET Command Prompt to open the Visual Studio .NET command prompt.
2. At the command prompt, change the directory to the SDK\v1.1\Samples\Tutorials \resources andlocaliz ation\rese ditor folder as shown below:
cd \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Samples\Tuto rials\reso urcesandlo calization \reseditor
3. At the command prompt, type Build, then press the ENTER key to build the application.
ResEditor is built and the executable is placed in the \Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\ Tutorials\ resourcesa ndlocaliza tion\resed itor folder.
Cheers
jatinder
For creating the resource file : -
The .NET Framework includes a sample application called ResEditor that facilitates creating and editing resource files. The ResEditor application allows you to create binary resource files (.resources) as well as XML resource files (.resX).
Building ResEditor
ResEditor is provided as source code with the .NET Framework SDK. Before you can use ResEditor, you must build it using the supplied batch file.
To build the ResEditor Application
1. Start Windows, and then click the Start button, point to All Programs, then Visual Studio .NET 2003, then Visual Studio .NET Tools, then Visual Studio .NET Command Prompt to open the Visual Studio .NET command prompt.
2. At the command prompt, change the directory to the SDK\v1.1\Samples\Tutorials
cd \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Samples\Tuto
3. At the command prompt, type Build, then press the ENTER key to build the application.
ResEditor is built and the executable is placed in the \Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\
Cheers
jatinder
ASKER
Hello Jatinder!
Thanks for your reply, I managed to locate and build the resource-file editor.
How to read the image from a resource-file?
Can you please send me a code example?
Let's assume I have example.jpg and I put it into the resource file with the tool. What to do then?
Thanks for your reply, I managed to locate and build the resource-file editor.
How to read the image from a resource-file?
Can you please send me a code example?
Let's assume I have example.jpg and I put it into the resource file with the tool. What to do then?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot!
I will soon try.
I have another urgend question related to that.
I created a setup up project for my app that works fine in Debug mode and also setup works fine in so far that all files and shortcuts are porperly installed on the target computer.
The only problem is that the relative path to some images does not work. I use this:
public Image DestiChart = Image.FromFile("charts\\de sti_ch.tif ");
My folder structure after installation looks like this:
MyAppFolder
-- charts
-- desti_ch.tif
-- ...
Time is scarce so I do not know, if I will manage changing all to the embedded resources right now. I have to deliver a test version in the next hour.
I will soon try.
I have another urgend question related to that.
I created a setup up project for my app that works fine in Debug mode and also setup works fine in so far that all files and shortcuts are porperly installed on the target computer.
The only problem is that the relative path to some images does not work. I use this:
public Image DestiChart = Image.FromFile("charts\\de
My folder structure after installation looks like this:
MyAppFolder
-- charts
-- desti_ch.tif
-- ...
Time is scarce so I do not know, if I will manage changing all to the embedded resources right now. I have to deliver a test version in the next hour.
If charts is the subfolder in application directory. Then you need to use @"\charts\desti_ch.tif"
ASKER
Thank you very much again for the instant response.
Unfortunately this did not help.
I always get a System.Reflection.TargetIn vocationEx ception in my .exe
We can open a different thread, if you want, you deserve good points for your answers!
Unfortunately this did not help.
I always get a System.Reflection.TargetIn
We can open a different thread, if you want, you deserve good points for your answers!
That's nice we can go for another thread.
ASKER
Hello Jatinder!
Unfortunately I can come back only now. I prefered to send out the first version without embedded resources but now I have to master them.
I made a number of tests and in priciple it works, but right now I find it very unhandy to have these three lines everywhere in my code.
In pricinple I would like to declare and initialize each image object once as I do when loading them from disk. I have about 30 images and all are needed frequently in the code so I would like to have each image represented by a short but clear name.
The problem I encounter is that I try to have the following lines only once in Form 1:
Assembly asm = Assembly.GetExecutingAssem bly ( ) ;
ResourceManager rm = new ResourceManager ( "Name of resource", asm ) ;
I would like to have a line like
puclic Image AppStart = (Image)rm.GetObject("AppSt art");
in the declaration part of my code, but the problem is that rm is unknown when I place the first two lines in Form1.
On the other hand I cannot put "public..." into Form1(), because "public" is not allowed there...
I hope you can understand what I am driving at and I hope you have a quick and simple solution for me!
Many many thanks again for helping me!
Unfortunately I can come back only now. I prefered to send out the first version without embedded resources but now I have to master them.
I made a number of tests and in priciple it works, but right now I find it very unhandy to have these three lines everywhere in my code.
In pricinple I would like to declare and initialize each image object once as I do when loading them from disk. I have about 30 images and all are needed frequently in the code so I would like to have each image represented by a short but clear name.
The problem I encounter is that I try to have the following lines only once in Form 1:
Assembly asm = Assembly.GetExecutingAssem
ResourceManager rm = new ResourceManager ( "Name of resource", asm ) ;
I would like to have a line like
puclic Image AppStart = (Image)rm.GetObject("AppSt
in the declaration part of my code, but the problem is that rm is unknown when I place the first two lines in Form1.
On the other hand I cannot put "public..." into Form1(), because "public" is not allowed there...
I hope you can understand what I am driving at and I hope you have a quick and simple solution for me!
Many many thanks again for helping me!
How about going for a singleTon design pattern for managing your resource manager instance.
This way you will always have a single calll from any form.
This way you will always have a single calll from any form.
ASKER
Ok, from your answer I see that obviously it does not seem to be a beginners mistake that I do not get it going in one line instantly.
Can you please explain to me what a singleTon design pattern is?
Maybe you have a link at hand?
Can you please explain to me what a singleTon design pattern is?
Maybe you have a link at hand?
These links will help you undersatnd the singleTon design pattern
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp
http://www.yoda.arachsys.com/csharp/singleton.html
http://www.c-sharpcorner.com/Code/2003/Jan/SingletonPattern.asp
Jatinder
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp
http://www.yoda.arachsys.com/csharp/singleton.html
http://www.c-sharpcorner.com/Code/2003/Jan/SingletonPattern.asp
Jatinder
ASKER
Thank you very very much for your extensive answers and the very quick responses!
Best regards,
i-Thomas
Best regards,
i-Thomas
RemoteSoft has a product which gives you the ability to distribute a .NET application to a computer that does not have the framework installed:
http://www.remotesoft.com/linker/
cheers