Form design from dll project other than from winforms project - c#

So when I create and do what ever I like to do with a winforms project on my Win10 PC, all the forms in that project have that kind of Metro Style UI design.
However if I create a dll project on the same PC, and reference to what I think is the same System.Windows.Forms dll as the winforms projects do, the forms I can create from the dll look a little bit as if I was on Win7 and had enabled the use XpVisualStyles option.
i.e.: As an basic example: all buttons on the form are set to a 3d border style by default and trying to get them to be flat is not that easy (if they should look good atleast)
Question is: Why do the forms created from the dll look differend than the ones created from a winforms application, althought they both reference the same dll (System.Windows.Forms I even checked hash and version)?
2nd Part how can I get the forms created from the dll to look like the ones from an winforms project?
Additional Information: The dll forms have been created by referencing the dll from 1 a console project and 2 an other winforms project. Both looked like Xp.

So thanks to the nice comment by #Reza Aghaei this question is solved.
1st Solution
Make sure that in the Application that opens the form the Appliction.EnableVisualStyles(); is called, this requires a reference to System.Windows.Forms if there is none.
The shown form will then look just like it shows you in the designer that it will.
2nd Solution
Call the Appliction.EnableVisualStyles(); inside the dll that owns the form.
This be done by
Calling in the constructor of each form
Or via some static function in the dll that takes care of all initialization
additionally there could be a conditional inside the form constructor that calls some function of the same dll that checks if styles are enabled and if not does so.
I would based on my knowledge commend to use a static initialization function.

Related

c# winforms - calling form from another dll (c#) missing show() and showdialog()

I have some project (app) in c# winforms(.net framework 3.5). Project is builded from few smaller projects. In all this smaller project there are some forms. Right now I need create seperate project (app) and I want use one of this smaller project by his dll.
I adding dll to project by reference, I see form that I need so I create object. I see some my custom proporties but I don's see basic methods like Show() or ShowDialog(). Honestly I don't know were is problem. I tired some someone else's dll from different source and different framework's and It's worked. So I'know there is problem in my 'main' app but I don't remember any proporties which disable visibiltes of this methods. What can I do to get all the methods back?
Project which I try using dll are library type. When I'm using it in that main app I see all methods.
Maybe I show screen:

Windows Forms Designer can't find DLL

I have a Problem with using Usercontrols from another Library.
I have a Project Solution in the Project Solution are two Projects (the Main Program and a Library) in the Library are my custom Usercontrols and some Objects which will be used from the Usercontrols. For example a custom List View which shows some informations from the Object that is given.
My Problems are:
that the Designer cant found the Library which I added over the Toolbox (choose elements...) and
that when I try to choose an Object instance (which should be shown) the designer says that it cant be found although the Object class is public.
I hope you can help me.

Cannot use Grid in VSTO Word Addin

In my VSTO application-level word addin, I'm trying to add a Grid to a UserControl in order to make its layout coherent.
However, when I try to declare the grid, Visual Studio complains that the type or namespace "Grid" cannot be found. I solved this error by adding the PresentationFramework assembly as a project reference and importing System.Windows.Controls, but now I have an even bigger issue: Visual Studio complains that "UserControl" is an ambiguous reference between "System.Windows.Controls.UserControl" and "System.Windows.Forms.UserControl".
I checked the top of my .cs file and found it already was importing System.Windows.Forms by default and now, it is also importing System.Windows.Controls.
I'm wondering why the VSTO project defaulted to importing System.Windows.Forms in the first place instead of System.Windows.Controls and what the main difference is between the two namespaces because in my WPF application I use System.Windows.Controls. Thank you!
From origin VSTO was a Forms based set of tooling, and XAML based UI option is only from later years. Obviously you still can use System.Windows.Forms and reference that in your XAML applications so when adding the XAML References there are some ambiguous items if both present (I always tend to run into the XAML and Forms MessageBox ambiguity interfaces) and you need to prefix the ambiguous items.
What I do is trying to be either full on the XAML side or decide to move to the Forms side.
Probably the VSTO, a somewhat older technology by now, project templating is based on the Forms libs to start with but you are free to move completely into the XAML world. My own solutions today are fully XAML based, but I fall back to Forms every now and then (doing a quick demo for instance).
So it is just a technology choice and VSTO is going back a long time so it started with Forms. Go with the new and shiny XAML technology if you like (I'm biased, I love that technology) or stick to the Forms technology. You can use them both.

Building wpf application as type of wpf class libarary

My need is to develop an addin for an application
but WPF application is not allowing to build it in type of WPF Class Libarary
Refering to this question i found that without XAML pages only we can build WPF application in Class Library Type. It it true? Or am I missing something?
I need to add a WPF window to my addin, but they are referring to remove all the windows and add usercontrol? Whats the workaround for it? Or am i doing anything wrong?
What i did now is I just deleted my application.xaml window from my solution and changed the target type to WPF class Libarary and builded the solution and it builded successfully. Is it correct way..? or any other ways there..? Am really new to this WPF !
There two additional templates to build WPF dll's such as WpfCustomControlLibrary and WpfControlLibrary. You will then be able to add a Window (and other WPF-specific elements). And it can certainly contain general-purpose classes. And it will be built into an assembly no different from that from general class library project.
How to: Create a WPF UserControl Library Project
How to add a WPF control library template to Visual C# Express 2008
If you want just create class libary, please, just select Class Library
How to: Create Class Library.
Also, you can add Window to general class library project. Visual Studio just does not expose Window from add new items dialog. A workaround is to add a User Control Item, and then change it to derive from Window.
Yes, you can go on creating a Class Library, adding a XAML view there. In your exe project you will include a reference to that lib and its public XAML windows or user controls should be available under the library's namespace, like any C# class.
Edit
A simple example from GitHub: as you can see, the library project is compiled with a reference to the System.Xaml assembly.
Edit 2
To build an already existing Windows Application project into a Class Library one, besides changing the Output type you have to delete only the App.xaml

C# WPF Library creating

I have a WPF project. I want to use this project in other new projects using a .DLL file, Like MessageBox form in C#, when we use MessageBox.Show to create a form.
Library project file cannot specify ApplicationDefinition element.
When i change the output of the project to "Class Library", the "InitializeComponent();" method makes an error, so does many other methods in the constructor of my window, saying
The name 'InitializeComponent' does not exist in the current context
How do i solve this? and how do i use my library once created?
You can't simply port it to a Class Library. You can hack at the app.xaml and so forth, but it would be best if you create a new "WPF User Control Library" or "WPF Custom Control Library". Migrate over your existing code to it. Make sure to expose Public classes and methods that you wish to call from outside of the library.
You can create a Solution to contain your new library as well as a test WPF Application. That way you can add a reference in the application pointing to your library project. Testing would be easier that way.
As far as how to use the library -- you'll need to do some research on that. There are a number of ways to go about it depending on your needs.
OK, the problem is that you project is an app, not a library. Just changing it to library in settings wont help.
The best this to do is to create a new project of type 'user control library', and then copy all of your xaml and classes over to the new project
Deleting App.xaml from my project worked.

Categories