Creating a CLR User Control - winforms

Under Visual Studio 2019, I would like to create a user control in C++/CLI.
I didn't succed to compil a dll.
What I did :
Create a new empty CLR Project (because I don't have the option to create directly a user control project)
Menu Project -> Properties -> Link editor -> System -> syb system -> Windows
Panel Solution explorer -> Right clic on Header files -> Add -> new element -> CLR -> user control CLR
I compil the project and restart Visual Studio (in order to access my component designer overwise the designer gives me an error)
I add some graphical elements on my control (buttons, labels, etc) and I compil
I try to find the dll in the release folder but I only find a *.dll.metagen and no dll
I tried to change : Menu Project -> Properties -> General -> configuration type -> dynamic library (.dll)
but it does nothing better
Thanks for your help

Found the solution :
At start, when creating a new project, choose : "CLR Class Library" as type of project
next You can do : Right click on "header files" -> add -> new element" -> "-> CLR -> user control CLR".
It compile and create a dll that contain a user control that can be imported in a windows form

Related

How do I view and edit Visual Basic Power Pack shapes in a Windows Form app with Visual Studio 2017?

I've got a windows forms app created in an older version of Visual Studio. When I open it in VS 2017, none of the Power Pack shapes are show in the design view. I've got the Power Pack dll in references. I tried to add them to the toolbox (General, Choose Items, .Net Framework Components), but the shapes like Rectangle Shape are missing. How can I either get them to display in the design view or add new ones through the toolbox?
Here is the reference to Power Pack:
Here's the choose toolbox item where you can see RectangleShape is missing:
Here's the code where the rectangle is defined:
private Microsoft.VisualBasic.PowerPacks.RectangleShape StandardFiltersToUseRectangleShape;
this.StandardFiltersToUseRectangleShape = new Microsoft.VisualBasic.PowerPacks.RectangleShape();
this.StandardFiltersToUseRectangleShape.BorderWidth = 3;
this.StandardFiltersToUseRectangleShape.Location = new System.Drawing.Point(626, 82);
this.StandardFiltersToUseRectangleShape.Name = "StandardFiltersToUseRectangleShape";
this.StandardFiltersToUseRectangleShape.Size = new System.Drawing.Size(600, 15);
this.shapeContainer1.Shapes.AddRange(new Microsoft.VisualBasic.PowerPacks.Shape[] {
this.StandardFiltersToUseRectangleShape,
this.FiltersToBuildRectangleShape});
You are looking into a wrong assembly. You need to look into Microsoft.VisualBasic.PowerPacks assembly.
Visual Basic Power Packs Controls are not included in Visual Studio by default. First you should download and install them. Then to add them to the toolbox:
Right click on ToolBox → Choose Items ... → Filter for powerpacks → Check controls → click OK.

Visual Studio Create Resource

In my Visual Studio 2015 WPF Project I want to define a new Resource for my UIElement. In the Documentation on the Microsoft Site (https://msdn.microsoft.com/en-us/library/hh921076.aspx) they say that you can choose a ResourceDictionary.
Following Steps are described:
Click the UIElement
On any Property click on the Little square on the right
Select "Convert to new Resource"
Choose your Option
In my Project the desired Option is not enabled. The only Option i can set is the "This Document" Option.
My Project has the following Structure.
Folder "Resources" which contains some XAML Files that hold single ResourceDictionaries
a ModuleResources.xaml file that merges all the Resource Dictionaries from the Resources Folder together
In the Project Properties i found a Option to define Resources, but those only allow Images/Strins/Icons.
Am i missing something?
Thanks for your help.
EDIT:

How to attach external script to existing Visual studio project

Attaching existing .cs file to windows forms application project
click on solution explorer.
Right click on project name, Add -> existing item.
Select the script you want to add.
In Form1.cs file mention following
using Namespace_of_attached_cs_file

How can I make Visual Studio 2010's "Add User Control" create a WPF control?

I have a class library that I created using the "Class Library" project template. If I right-click on this library in Solution Explorer and select "Add > User Control", Visual Studio adds a WinForms UserControl. That's not what I want -- I want "Add > User Control" to add a WPF user control.
I've already added references to the WPF assemblies (WindowsBase, PresentationFramework, and PresentationCore), and I already have some WPF UserControls in this library, and everything compiles. My library does not have references to the WinForms assemblies (System.Drawing and System.Windows.Forms). But apparently the proper references are not enough of a clue for Visual Studio, because when I try Add > User Control, it adds the WinForms references to my project, and then creates a WinForms UserControl.
I can add a WPF User Control to my WPF Application project, and then move it into my library. But that's a pain, and I'd rather have it work properly in the first place.
I think I'm probably missing some kind of arcane XML element in my .csproj file that tells Visual Studio which designer to use by default, and if I add the right XML element with the right cryptic GUID, it will start working properly. If I could create a new WPF Control Library, I could probably compare the two project files and figure this out. However, I'm using Visual C# Express, which doesn't have a template for a WPF Control Library project, so I'm out of luck there.
What do I need to do to my Class Library's .csproj file so that VS2010's Add > New User Control will add a WPF UserControl?
There are sub-projects class ids in the project file that affect the Visual Studio context menus and how the project behaves in general. The easiest thing to do is to recreate the project as a:
WPF User Control Library
instead of a "Class Library". It is possible if you already created the project to edit in the sub-project class ids by hand by opening the ".csproj" file in a text editor such as Visual Studio itself but its easy to cause more damage than you fix that way.
I believe but haven't test that another type of library will also work:
WPF Custom Control Library
which is intended to hold other types of controls than UserControl objects but being a WPF sub-project type the context menus also work correctly for the use case you are describing.
Edit:
For completeness, I've just tested how to manually add the sub-project GUIDS. Add this line to the first PropertyGroup in the .csproj file:
<PropertyGroup>
...
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
Not tested with Visual Studio Express.

How to compile a WPF application into a class library and start the application when needed

I am wondering how to compile a WPF application into an independent shared class library(dll)? Any sample?
Solution Explorer -> Right Click on "MySolution" -> Add -> New Project -> WPF User Control Library
Add your controls there and use from any other application.
Convert your current project to dll: Solution Explorer -> MyWpfApplication -> Right Click -> Properties -> Application Tab -> Output Type = Class Library
Or you can add references from other Applications to your existing project even if it's exe. (Controls are still available)
A library is not an application, so we can't convert a WPF application to a dll and expect to be able to run it independently.
One workaround might be to change the projects output type to "Class Library", then create a new WPF application which hooks into the dll.
To make the new application hook into the dll, first add a reference to the dll, then edit App.xaml and change StartupUri to a pack Uri pointing to the dll.
<Application x:Class="WpfApplication13.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="pack://application:,,,/ReferencedAssembly;component/MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

Resources