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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With