How do I switch between two apps seamlessly? - c#

I have a .NET application that was written in C# and VB.NET using WinForms. We want to slowly migrate this to something new, in many iterations. The new code will be entirely C# and WPF. We would like to utilize Prism.
As far as I know, we can't integrate the old WinForm app in Prism.
I am considering making my old app show the new app in certain instances. For example, when you press a tab in the old app, the new app opens on top of the old app, with the same tabs. Over time, only the new app would be necessary.
How can I do this?

Like my comment above if you HAVE to do this hack I would start creating WPF Controls and ViewModels and integrate then in WinForms. So your slowly replacing Forms in your Winforms app with WPF Control, Pages, and Windows. Here is a tutorial to get you started
Keep in mind you should be creating a WPF during the side at the same time. That way when your like 85% done you can just concentrate on the WPF app.

Related

WPF and CefSharp: sluggish performance

I have successfully made a personal mini browser app in c# winforms.
Because I want some more fancy effects, I was considering to make a WPF app. So I tried the wiki tutorial and set up a simple WPF form with a browser, but noticed it has sluggish performance. It's even noticeable when selecting text in very simple webpage, or just when scrolling the page. Is there anything that can be done? If not, I guess it will be just winforms then, since that one behaves and performs well.
edit: my specs: http://users.telenet.be/dropbox/specs.html
WPF version of cefsharp uses different model of rendering than WinForms. In WPF it basically copies each frame into bitmap and you might imagine how slow it can become. This is especially noticeable on high-resolution screens. There are some options to improve that perfomance (see here for example), but in my experience (I tried all that options) non of them really helps to match WinForms. To run cefsharp smoothly in my WPF project I actually had to use WinForms version of cefsharp and host it inside WindowsFormsHost - this helps with perfomance problems but has it's caveats of course (for example you cannot partially hide WinForms hosted control behind WPF controls - it will always be rendered on top of everything). Still for now I consider this the only viable option, because high-resolution screens are now quite widespead.
This will disable WebGL, look at the source to determine which flags best suite your requirements. "grMain" is a Grid in Wpf
CefSettings s = new CefSettings();
s.SetOffScreenRenderingBestPerformanceArgs();
Cef.Initialize(s);
ChromiumWebBrowser wbMain = new ChromiumWebBrowser();
grMain.Children.Add(wbMain);

C# Hosting WPF in Winforms

I am looking at the possibility to host a WPF control inside a Winforms application. The reason for this is some animations inside the WinForms application. WPF should be able to support this way better because it (mostly) uses the graphic card to render instead of the CPU.
Now my question:
Are there any cons of hosting a WPF Control inside a Winforms application? Does the WPF Control still use the graphic card for the rendering or does it loose some of its advantages?
Thanks for your help. If you have any inputs or tips feel free to tell me.
EDIT
I found a similar question (but maybe that one is a bit more general, I focus more on the rendering):
Any disadvantage to using an ElementHost to host a WPF UserControl in a Winform application?
Mainly it behaves very like in a normal WPF Application.
But sometimes there are little unexpected behaviors. And it should use the hardware rendering if it would be using in normal wpf applications (depending on your configuration)
Sometimes i had problems with correctly recevien some keyboard keys in events. but there are a lot of artikels descriping the problems and solutions.
For example with some controls you could have problems catching keys. So you should have a look at System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop
-> also see this blogpost

Running a WinForms Application Inside Web Browser

I have a win form application and i'm trying to run it inside the web browser,i rummaged through web and found some links:
I tried this link:Embedding a .NET WinForms Application in an Internet Browser Using WPF
,this works fine but the problem is that the end-user has to install dot net frame work for running the application.
I found another link here for running a WinForms Application Inside Web Browser,with Visual WebGui development framework.
Has anyone had any experience with WebGui?
Well, Visual WebGui is web over ASP.NET. Its developing experience is the same/similar to that of Windows Forms using the Visual WebGui designer integrated into Visual Studio. You do your code behind just the same as you would on Windows Forms and the WebGui runtime transforms it into HTML5/CSS/JS.
The efforts needed to convert your Windows Forms application to a equivialend Visual WebGui web application will depend on the (3rd party / .NET) components used in your Windows Forms application. The Visual WebGui API is farily similar to that of Windows Forms, so in some cases you can add a few references to WebGui specific assemblies and then to a search/replace for a couple of namespaces. There are of course some differences, as these are two different platforms, but the developing experience is quite similar to Windows Forms.
winforms is not web. Web is Web.
Web means HTML + something (usually JavaScript, CSS and probably jQuery or such).
1 - If you need a web application, and want to do it with .Net, create an ASP.Net Application.
2 - If you need a Windows application (Desktop), create a WPF application.
3 - If you need a Windows 8 "Metro" style application (a.k.a Windows Store App), create a WinRT XAML application.
4 - winforms is completely useless. Forget that.
If your customers don't want to install any version of the .Net Framework, your only option is #1.
A winforms application will NEVER be a web application, regardless of any hacks you do to make it run inside a web browser.
an XBAP (WPF Browser Application) is also NOT a web application. It's just a regular WPF client application that does not have it's own window.
Edit:
If you did things the right way (that is, maintaing separation of concerns and putting application logic in Controllers or ViewModels instead of the horrible code behind practices most winforms developers are generally used to), It should not be that hard to reuse your application logic and create a new application (web or otherwise) while maintaining the Data Access and Business Logic layers intact.
I think this question is very similar to this one:
Is it possible to convert a WinForm to a WebForm in .NET?
As mentioned before, the only way to run the application "as is" inside a browser will be through the use of some activex control and that would require IE + .NET Framework.
There are tools that you can use to automatically migrate the application to the Web, but there will always be some manual effort involved and it won't be the same as building the application from scratch as a web app.
In my limited experience with Visual WebGui, it is pretty cool technology. In simple terms, as I understand it, you can use the Windows Forms development IDE to create an HTML5-compliant ASP.NET client/server web application... not just a web site or page, with a look and feel very much like a Windows forms desktop application. It does this by converting Winforms controls to jquery code on the client side, and stores most of the executable code on the server side.
I've used it to create simple applications for testing purposes, and there are a few caveats. First, to create a "pretty" website, you need to rethink the Winforms layout to make it web-like, with headers, sidebars, etc. It's a different paradigm, and users expect certain things on a website. The good news is that this adjustment can often be done fairly easy by simply manipulating controls; i.e. a Panel control can become a container for a sidebar or header. You can also create "themes", which are like skins for the controls to modify the appearance.
Another consideration is that events for things like popup dialog boxes behave differently in a web environment. In Winforms program execution halts until the user clicks an "OK" button or something. Within Visual WebGui, all the execution happens on the server side; thus, program execution would continue without waiting for user input. This can be handled by creating a Form.Close handler for the popup box though. But these kinds of differences need to be kept in mind.
You also must consider object layout anomalies. Visual WebGui does a good job generally of mimicking the Winforms WYSIWYG benefit: Objects normally appear pretty close on the webpage to where you put them in the environment. But this isn't always the case; you need to play around with object padding, margins, etc. sometimes to get the right layout. Still it is often much easier than tediously changing spacing with CSS or div objects.
Thinfinity VirtualUI allows you to do so by adding a small line of code to your C# application so it can then be accessed from any OS and device via an HTML-able browser.
https://www.cybelesoft.com/thinfinity/virtualui/web-integration-for-windows-apps/
I've used VWG but it's not really an option anymore. One option not mentioned here is WiseJ, a proprietary framework which is still under active development and support in 2022. And it is fairly straightforward to convert a WinForms app to WiseJ, or begin using WiseJ like you would WinForms.
They are located here: https://wisej.com

Use a webpage as the UI in a C# desktop application?

I'm building a C# desktop app with a simple UI. Due to my familiarity with HTML/CSS, and a previous web-based iteration of a very similar app, it would be ideal if I could re-use some existing HTML/CSS pages I have as the UI for this new desktop app.
Is that do-able with C#? Can anyone show a simple example of using an HTML/CSS page as the UI of a C# desktop application?
Other answers are dated, new good options:
Electron + Electron-Edge - is the way to go for a new Electron app that communicates to a .NET backend (a DLL). Widely used and supported.
Neutronium - best for already-written .NET WPF apps that need a HTML UI. Requires using Vue. Less popular and less supported.
CefSharp (https://github.com/cefsharp/CefSharp) is a good way to embed chromium, but you still need a web server. Take a look at http://www.ultidev.com/products/Cassini/ to alternative for IIS.
You can use WebBrowser control to add Web browser functionality to your application.
You can create your own html(s) and set your WebBrowser control to display those pages. You can navigate by clicking hyperlinks or by using keyboard shortcuts to move backward and forward through navigation history. By default, you can access additional browser functionality through the right-click shortcut menu
You can even manage those pages centrally (for e.g. on LAN) and all clients on LAN can connect to this central location. This way you can modify pages centrally.
Check a walkthrough on MSDN:
How to: Add Web Browser Capabilities to a Windows Forms Application
You can try to use a Chromium-based control - DotNetBrowser. This control provides wide interactivity options, like DOM manipulation and DOM events, which can be useful in your case.
In addition, there is an article that demonstrates how to use a web page as HTML UI in a C# desktop application: https://www.infoq.com/articles/html-desktop-net
Affiliation disclosure: I work with the team, which created DotNetBrowser.
You could try adding a Web Browser control to a forms application to show your page. But this will need to be remotely hosted as the code will not be able to execute locally, except if you listen for the specific links in c# and then perform the actions.
You could also try your hand at WPF which is a new technology to create good looking gui's with mark-up much like html, which you'll pick up pretty quickly with your html experience.
Unfortunately neither WinForms or WPF is sufficiently like HTML/CSS to be of that kind of use. You'll be able to reuse the layout-concepts and art of course. And, with WPF being the closest thing to it, you might even keep a lot of the code-behind code.
But the short answer is: No

Is WPF still relevant and can I use it in my C# windows application?

I have a process which I break into multiple processes and even when using threading it takes a very long time to complete.
I'd like to give the user an indication of the status of the execution in a cute way (for each process % complete). Maybe betting on the right horse will ease the pain :)
I found this project long ago: A Guided Tour of WPF (XAML)
I have two questions:
This article was written in 2007. Is there better way to achieve this graphic effect?
I have not understood yet, how the application is started, so I'd like to know if I can integrate such "window" in my window application?
Adam Robinson pointed out that the second question is not clear:
The application generates a window as in the picture below - I like to know if it possible to insert it in my "normal" windows application.
This article was written in 2007, is there better way to achieve this graphic effect?
WPF is the current "best" (or at least most feature-rich) way to develop a Windows Application for the desktop.
I have not understood yet, how the application is started, so I'd like to know if I can
integrate such "window" in my window application?
Make your application a WPF Application. This will automatically give you an application, Window class, and everything else you need to get started. Making a WPF application is just like any other application, except that you need to start the message pump, create the application, setup your startup window, etc. The "WPF Application" template in Visual Studio does all of that for you...
Until you understand what all is happening, I'd recommend starting with that, and customizing from there.
If you choose to stick with a win form for the main app, you can still host the desired window/control via an ElementHostControl. (hosts wpf inside winform).
Blessings,
Jeff

Categories

Resources