Embedding Images in WPF User Control? - c#

I have created a WPF control which I have embedded in a windows application. I have created an ImageBrush and set its source from the code behind as
imgBrush.ImageSource = new BitmapImage(new Uri(#"Images/imagename.jpg", UriKind.Relative));
This works fine when I am running the project from visual studio but when I install the setup and then run the application I get path not found error.

You can add the images folder to your installer project through visual studio, see here:
http://msdn.microsoft.com/en-gb/library/vstudio/4ddxk2ye(v=vs.100).aspx
Or to embed the image in the executable, just set the build action of the image to "Embedded resource" (in the properties dialogue in visual studio solution explorer)

Found the solution. Apparently when you embed the WPF control in a Winform application then you have to add the resource to the Winform application. I added the same image as a resource in the winform application and it worked.

Related

Where is the "project file"?

I have created a .NET7 C# project, and I'm trying to understand this article: https://learn.microsoft.com/hu-hu/dotnet/desktop/winforms/whats-new/net60?view=netdesktop-6.0#new-application-bootstrap about the new bootstrap that moves the configurations to the "project file":
To complement the new application bootstrap feature of Windows Forms, a few Application
settings previously set in the startup code of the application should be set in the project
file. The project file can configure the following application settings:
The only thing it doesn't mention is where can we find the project file? Is it editable from Visual Studio directly? Or we have to create it for ourselves?
In visual studio explorer, double click on the file with "csproj" extension (it has a rectangular icon with C# written in green. This will open the file in xml format. In most cases, you don't need to manipulate it manually.

C# Add external user control to project

I'm working on a windows form application in C# VS2010.
I found on the internet an implementation of a User-Control that I want to use in my project.
Problem: how can I import or include it so I will be able to see it in my Toolbox ?
I copied the UserControl directory into my project directory(see attached photo)
and then build the project and got this warning:
Error 1 Unable to create a manifest resource name for "RecessEditorControl.resx". Could not find file 'C:\Users\bassam\Desktop\comm\Projects\Thunder Archive\Thunder Archive\RecessEditorControl.cs'. Thunder Archive
any idea how it should be done?
Open the user control project separately (outside of your solution) and attempt to build it.
If the build fails, search for help from the control author(s) on what dependencies are needed and how you can build the control.
After you get it sucesfully built, there will be a .dll file in the bin/ folder (where config is most likely debug or release, depending on what configuration you used to build the project)
Reference this .dll from the windows desktop solution you are working on. Add it to the references section of your UI project.
It should automatically show up in the toolbox if it is properly coded as a user control.
There is the option of including the entire source project of your control in your win app solution, you can try this later if you verify that you are able to build the control on it's own.
Although I would not recommend this approach unless you intent to actively continue developing the user control.
You separately build user control to create a dll. After that include the dll in your app executable folder. When you switch to designer, you will see the control appears on the toolbox with the control name. Just drag n drop...

Fonts In WPF Project

How can i embedded the font with project when i publish it. because when i publish the project the used font type doesn't appear.
FontFamily="GE Thameen"
How can i embedded the font with WPF project when i publish the project ?
Check out the MSDN page for details of how to do this.
You should use it as a Resource.
Right click your project -> Properties.
Go to Resources and add Existing files.
Visual Studio will create a folder called 'Resources'. Remember to set the your fonts as Resources and not Compile!
Nice work, man!

C# Visual Studio 2010 embed exe icon

I have made an anplication with Visual Studio C# 2010 Express, and I have set my icon in the project properties -> application -> ressources ...
like this
but when I try to launch my app, I need to copy my icon in the same folder of the application
How can I embed it ?
What you've done is to add a pointer to a file on disk; instead, it's probably simpler to link the icon directly into your executable as a resource.
This page shows how to add an Icon resource to your .NET application: http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx
Once you've done this, you can point to the application icon that is compiled into your program, and it won't have to live on disk in a separate file.

How do I embed a banner image and or add remove programs icon in my setup project?

I'm using a setup project in visual studio 2010 to create an installer for a program I'm working on. I want to have a custom banner image in my setup as well as a custom icon in add remove programs.
I've added both these images to the "Application Folder" of my installer and was able to get them to show up correctly. However, my program is not very big and only installs as an EXE and a few DLLs. So it seems a little silly to me that the 4th and 5th files that get "installed" are graphics only used during installation.
Is there some way I can embed these images in the installer or one of my other projects?
I'm currently using VS 2008 and just been playing around with the setup project. I believe the following works - it did in my tests.
Select the setup project in the solution explorer window.
Right click and select Add/File
Find your banner Image file and add it.
You will see that it's been added to the Application folder.
Select the banner file in the application folder - or in the project list on the solution explorer.
Open the Properties Window
On the properties set "EXCLUDE" to TRUE.
When you set exclude to true you will see the banner file removed from application folder - but it will still be shown in the project tree - the icon will for the file will have a little red circle with a line through it.
I've done this with both the banner and a custom icon and tested my install - worked fine with both and neither file showed up in the application folder.
Hope this helps.
In the setup project properties you can put an image for the add/remove icon in the property AddRemoveProgramsIcon
For the banner image, right click on the setup project, View -> User Interface, click on the page you want, and then in the properties you want the BannerBitmap property.
This blog discusses a way to change the banner image without modifying the Visual Studio project.
If you want to change of the icon of the application EXE, then you just need to right click on the EXE and "create shortcut". In the properties you will find the icon and you can change it.

Categories