Getting Image to display in form - dll file - c#

I have a vb.net form application in which i have displayed a logo from Application startup path using the code
Application.StartupPath + ("\Image\" + "Logo.jpg")
This works and the image displayed as expected. This exe is called from jquery using AciveX and hence it works only in IE.
I have converted the vb.net form application to dll by referencing the exe created. Now, when i call the dll function from another application, the form appears but the logo is not displaying.
I have used edge to read dll files from node.js application.
Please help to get the image to be displayed in the form when reading using dll file.

Did you check your image path at runtime to ensure it was resolving correctly? If your dll is in a different folder than your calling application, Application.StartupPath may not resolve as expected.
I was having a similar problem, but referencing an image in my resources manager. I realized when I transferred the form from an application solution to the dll solution, my PictureBox lost the default setting of its "Image" property in the designer, so it wasn't trying to set any image at all.

Related

How to edit assembly resources/or settings dynamically in C#?

I am working on a POC, Where we need to "Extract" an EXE out of another EXE resources,
But before we extract that exe file, we need to assign some values to it so it would work successfully, or to take actions based on this "seeded" value.
for the child exe, I have tried using "Resources" and/or "Settings".
In a nutshell.. how to edit another exe file resources value!
Please see the attached image for better understanding:
I have tried using Cecil library, but it doesn't seem to see/explore the child exe (Resources) instead it's showing the forms with in the child exe

Errors after changing tool strip button image

Once i add this line to the code:
this.tsbAdd.Image = Bitmap.FromFile(#"..\..\Resources\add.bmp");
I'm unable to open editor of that form.
Screenshot of designer
I can compile app and images work as they should.
Expected results - new image is displayed without breaking designer.
Real results - new image breaks designer.
Once i build it into .exe it doesn't open. Without images it works flawlessly.
Nope it won't. The picture will be built, but referencing it by this path won't be working.
The resource file WOULD be built into your exe, but not at "....\Resources\add.bmp". This path only exists in your IDE configuration position, when your program is at "bin\Debug", you understand me?
Imagine you put your exe into C:\, then where is "....\Resources"? You cannot refer to a image in this way.
You should add resources in the project panel (I believe you have done that), and the way you get this file is via ResourceManager, not using this path. Like this:
ResourceManager rm = Resources.ResourceManager;
this.tsbAdd.Image = (Image) rm.GetObject("add");
The resourcemanager will pull the resource bitmap out from your built exe. Just using that path won't work. As the designer is not ran in \bin\Debug, no wonder it is broken too because it cannot find your file using that path.

Deploy .json file with UserControl WinForms

I have built a custom User Control in Visual Studio (Win Forms).
This User Control requires a .json file to be deployed along with it.
Short Version: How is this possible?
Long Version:
When I am testing the User Control from with the Control designer itself, it works no problem.
This would be because I have set the following:
Build Action to Content and;
Copy To Output Directory - Copy if Newer
So when I'm debugging it, everything is there, as I expect it to be.
The problem occurs when I create a separate Win Forms application, and add this newly designed control to the Palette by:
Right click Toolbox->Choose Items->Browse->Browse to the Project Directory of the Control->Select the DLL->OK
It show up on my Palette, but the problem is of course when I drop the User Control onto the form itself. It has no means of getting "MyFile.json" from User Control Application/Dll to the Current Project.
How do I make this work?
Chud
One easy way is to build your json file as a EmbeddedResource instead of Content. That way it will be embedded into the UserControl's binary (the dll file itself). You can then use ResourceManager class to read it in your code.
If you're going to change the content of json file at runtime, you can instead create an application setting of string type that stores the actual json content. This setting can then be read/written easily using ProjectName.Properties.Settings.Default.YourSettingName.
Also note that if you have set your json file's Build Action to Content and Copy to Output Directory to Always Copy, and you add a reference to this project from another project that also exists in that solution, the content file (json file) should get copied to the bin folder correctly. But if your UserControl project does not exist in the current solution, or you're referencing your control through Browse button, you'll not get your content files. This may not seem obvious, but once you think about it, you'll understand that VS cannot figure out what dependencies does a DLL file has if you simply add a file reference.
In the latter case, a setting is the cheapest solution (described above) that you can use.

How to load/link dynamically DLL which was already referenced in project (copy local false)

In resume, we want to use the CefSharp dll to embed a browser in our .NET app.
We don't want to add size to our setup since the dll size is quite large.
Here is what i try to do :
I reference the DLL in my project as Copy local to false which when
compiling will not link the DLL in the files.
Before using the cefsharp class in my code i download the DLL plus all the file needed and extract it where the app .exe is located
This is where i hit a wall, if i try to use the cefsharp class after everything is done at the good place the cefsharp will not work
which is normal because the dll have not been loaded (unless an app restart).
Is there a way
to dynamically link my already referenced dll in memory, so i don't
have to restart my application?
Thanks !
I ended up restarting my app...

how can i assign external images which loads in both runtime & design time with relative path to where the exe is built?

I want to create a guide application using C# which contains screen shots , texts and links to other pages.
I know that later on I have to update the guide application with its images.
The application including images is arround 2 MBs for each language. so I want to update it with the differences.
The solution i was thinking of is having a simple exe with PNG files next to it.
So I just need to include the exe and the only PNG files that have changed in my update patch.
The exe loads PNG files using PictureBox.ImageLocation attribute with relative path to where the exe is built. it runs ok. everything is fine but in Visual Studio's Designer it fails to load the images. It shows a cross sign on the Picturebox. The ErrorImage. I want to keep it relative because I use several PCs or maybe a team for the future.
Here is a sample project:
https://www.dropbox.com/s/o20xzc96cv422g9/WindowsFormsApplication3.rar
Runtime:
Designer:
Works ok at runtime, fails at designer.
how can i assign external images which loads in both runtime & design time with relative path to where the exe is built?
Is there a better way to create low size patches?
The problem is fixed by putting the images inside the resources of many Class Library Projects. So the project can be divided to so many parts, each part has its own data that can be updated later with lower sizes.

Categories