Host C# winforms in VB6 applications - c#

I have a VB 6 application and we are starting to port it over to C#. We have finished one of the screens and wanted to see if there was an incremental way of hosting the winform within VB to start to have the existing users get used to new screens. This is a migration strategy..
Any thoughts.

The Interop Forms Toolkit allows you to create .NET Forms and User Controls that can be used in VB 6.0 applications. This allows you to migrate VB 6.0 applications to .NET over time (a form or part of a form at a time). However, the toolkit relies on features from the Microsoft.VisualBasic assembly and the VB.NET compiler so it doesn't work with C#.
There are a couple articles/samples on CodeProject.com that discuss the toolkit and how to use it with C#.
Interop Forms Toolkit 2.0 Tutorial
VB6 - C# Interop Form Toolkit
Beth Massi has several articles and webcasts on the use of the Toolkit you can use for reference. Check out her blog for links to resources.

Have you looked at this? Direct Link to Product here

You do not need any third party tools out anything outside of what comes with Visual Studio if you mainly just want your VB6 program to cause a .NET Winform to be displayed.
The approach we have taken here is to expose a C# wrapper class to VB6 by giving it a COM interface. This class has a few methods which can be called from VB6. They, in turn, instantiate and then show the Winform. It works well.

Related

Is it possible to write common graphics code to render visualizations on different platforms (Windows 7 and above/Android/IOS/ Windows mobile)?

We have a custom built data visualization control to draw charts. It was developed using win GDI APIs and the application is built using C++ COM/ATL.
Now we have a requirement to port this module to C# .NET (for maintainability).
The requirement is that the ported .NET control should work in Windows 7 and above (preferably Vista also). The straight forward approach is to start porting the code and replace the C win GDI APIs with .NET GDI+ APIs.
However one additional requirement is to investigate the possibility of reusing the newly written C# .NET code and deploy the same as apps in IOS/Android/Windows mobile (cross platform). I have come across Xamarin, but it looks like I cannot reuse the C# .NET code containing win GDI+ APIs directly.
Q1) Is it possible to reuse the ported GDI+ C# .NET code for developing mobile apps (may be using Xamarin)
Q2) If the answer for above is No, and we chose to start developing the control from scratch(in contrast to porting), What are the alternative approaches? i.e. what rendering libraries can we use?
Suggestions regarding existing visualization libraries which can be used in Xamarin, so that the developed app will work on all platforms are also welcome. The catch is the library needs to provide flexibility for us to add custom interactions to the visualizations.
Thanks!

Using WPF dll's in UWP app

I'm writing a UWP app, and for some reason I'm unable to reference PresentationFramework.dll. It contains some WPF controls I want to use (specifically, System.Windows.Controls.DataGrid, but they aren't available under Universal Windows >> Extensions in the reference manager. Why is this, and how can I fix it?
TL;DR: You can't use WPF controls in UWP.
WPF and UWP are two totally different APIs with a different .NET framework. While WPF has access to the full .NET Framework, UWP has a much more limited API. If you want to read more on the different platforms and compilers, this msdn blog post is a good entry point.
You are thus unable to add any standard dlls as a reference to an UWP app. If you want to share code between WPF and UWP, you'll have to use a Portable Class Library, in which you target the platforms you need.
And as the XAML namespaces for WPF and UWP are different as well, you won't find many portable controls. So for UWP development you'll need to use UWP controls (equivalent to their WPF counterparts). Bonus tip: if you're looking for 3rd party controls, you can also look for 'winrt' controls as winrt was used for Windows 8/8.1, but it's the same technology.
I know this is an old question. Not even going to research what came out when. There is a DataGrid for UWP as part of the community toolkit:
https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/datagrid
It's really frustrating though, because it doesn't seem to do a few things that the WPF version does, and these are the few things I needed it do do.
Microsoft really needs to come up with a new naming conventions for its 114 different frameworks and platforms. Controls should be named DataGridWpf, DataGridUwp, etc.
It's super hard to search for examples of the UWP DataGrid control and find thousands of examples for the WPF version. Just my two cents. And for the record, it seems like there are about 5 active links to examples on the UWP version. Arrg.
/And for added fun, Telerik and DevExpress have UWP data grid controls, which they also call DataGrids.

Integrating WPF application with WinForm application

I have an winForms application fully written in VB.NET. I have to start importing this application into WPF written C#. For the starting, I want to do this only for one module of the application. Is there any way I can pass VB.NET objects to a C# code, call a WPF application from a WinForms application and vice-versa ?
How should I approach this problem? Any help would be appreciated.
There is no easy way to migrate winform applications to Wpf.
You should carefully consider the reasons why would you like to do it and the effort it will take vs the profit.
that being said you can start by hosting your winform by a wpf application using WindowsFormHost then you can start by rewriting your controls one at a time and using ElementHost to host them in the winform.
Since you would like your application to be robust and use MVVM I personally think that it will take too much effort to migrate and it will be more reasonable to rewrite the application using already existing modules(logic not ui modules)
Regarding using Vb.net object in c# it can be done easily because they are both managed languages and are being compiled to CIL:
During compilation of CLI programming languages, the source code is
translated into CIL code rather than platform or processor-specific
object code. CIL is a CPU- and platform-independent instruction set
that can be executed in any environment supporting the Common Language
Infrastructure, such as the .NET runtime on Windows
Yes u can call wpf application in windows and vice-versa.For that u have to configure in .config file
In Through ElementHost u can access the controls

C# Charting Library

I've been looking for a good cross-platform charting library to use on a .NET project intended to be run on both Windows and Linux, but everything looks to have a dependency on WinForms controls, seemingly including ZedGraph (not to mention that ZedGraph looks a bit, well, dated).
Microsoft's Chart Controls for WinForms/ASP.NET look great, but like I said, have a dependency on WinForms controls. I know Mono includes WinForms support for Linux, but I'd rather not have to have Linux end-users install WinForms for what's going to end up being a GTK# application.
Does anyone know of any .NET charting library out there that don't depend on WinForms and that has good visual appeal?
P.S. As an example of a nice visual style, on a different PHP-based project, we use pChart (which I would link, but I don't have enough rep for it).
P.P.S. I've thought about using the Google Chart API, but I don't want to require a network connection just to generate charts.
They require Windows.Forms, since GDI (graphics) functions reside in that particular library. Any other chart control will have to use either 3rd party library or provide its own graphics toolkit.
The best thing I could find is Apache FOP:
http://xmlgraphics.apache.org/fop/
You should be able to run it from command line, or integrate it using IKVM.
Finally, why don't you want Windows.Forms library? As far as I know, mono provides a sufficiently working one.

C# controls in a MFC Application

I am responsible for the User Interface of an application written completely in Visual C++ using MFC and some third-part controls. I would like to use C# (WinForms or even better WPF) to improve the application look&feel.
I would like some advices about how to do it. Links, articles, examples...
Right now the user interface is isolated in a single project and I don't want to compile the whole module with CLR. So how do I have to manage that from the architectural point of view?
I have already looked at the Internet for the subject and read MSDN information. I would like more detailed information...is it convinient? pros/cons? have you used this approach successfully in a "big" application?
I don't want to compile the whole ui project with CLR...can I just have all the .NET code in a isolated project and call it from the ui project? what's the best way to do it?
Thanks in advance.
A good starting point is the Win32 and WPF interop page on MSDN.
I found this codeproject article gave a good introduction to the subject of mixing mfc / winforms code.
When faced with the same problem, I made an ActiveX control in C# and used it in my MFC app. The folks at MS took out support for building ActiveX controls with .NET, but it's still possible to do so with a plain Jane COM class which has a custom [ComRegisterFunction()] and [ComUnregisterFunction].
Although MS would like to tell us that the /clr flag will solve our problems, it measurably slowed down my large MFC app.

Categories

Resources