简体   繁体   English

在 Web 浏览器中运行 WinForms 应用程序

[英]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:我有一个 win 表单应用程序,我试图在 web 浏览器中运行它,我翻遍了 web 并找到了一些链接:

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.我试过这个链接: Embedding a .NET WinForms Application in an Internet Browser Using WPF ,这工作正常,但问题是最终用户必须安装dot net frame work才能运行应用程序。

I found another link here for running a WinForms Application Inside Web Browser ,with Visual WebGui development framework.我在这里找到了另一个链接,用于在 Web 浏览器中运行 WinForms 应用程序,使用 Visual WebGui开发框架。

Has anyone had any experience with WebGui?有没有人有任何使用 WebGui 的经验?

Well, Visual WebGui is web over ASP.NET.好吧,Visual WebGui是基于ASP.NET 的网络。 Its developing experience is the same/similar to that of Windows Forms using the Visual WebGui designer integrated into Visual Studio.它的开发体验与使用集成到 Visual Studio 的 Visual WebGui 设计器的 Windows Forms 相同/相似。 You do your code behind just the same as you would on Windows Forms and the WebGui runtime transforms it into HTML5/CSS/JS.您可以像在 Windows 窗体上一样在背后处理代码,WebGui 运行时将其转换为 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.将 Windows 窗体应用程序转换为等效的 Visual WebGui Web 应用程序所需的工作将取决于 Windows 窗体应用程序中使用的(第 3 方/.NET)组件。 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. Visual WebGui API 与 Windows 窗体的 API 非常相似,因此在某些情况下,您可以添加一些对 WebGui 特定程序集的引用,然后添加对几个命名空间的搜索/替换。 There are of course some differences, as these are two different platforms, but the developing experience is quite similar to Windows Forms.当然有一些差异,因为这是两个不同的平台,但开发体验与 Windows Forms 非常相似。

winforms is not web. winforms 不是网络。 Web is Web.网络就是网络。

Web means HTML + something (usually JavaScript, CSS and probably jQuery or such). Web 意味着 HTML + 某些东西(通常是 JavaScript、CSS 和可能的 jQuery 之类的)。

1 - If you need a web application, and want to do it with .Net, create an ASP.Net Application. 1 - 如果您需要一个 Web 应用程序,并希望使用 .Net 来实现,请创建一个 ASP.Net 应用程序。

2 - If you need a Windows application (Desktop), create a WPF application. 2 - 如果您需要 Windows 应用程序(桌面),请创建一个 WPF 应用程序。

3 - If you need a Windows 8 "Metro" style application (aka Windows Store App), create a WinRT XAML application. 3 - 如果您需要 Windows 8“Metro”风格的应用程序(又名 Windows Store 应用程序),请创建一个 WinRT XAML 应用程序。

4 - winforms is completely useless. 4 - winforms 完全没用。 Forget that.忘记那个。

If your customers don't want to install any version of the .Net Framework, your only option is #1.如果您的客户不想安装任何版本的 .Net Framework,您唯一的选择是 #1。

A winforms application will NEVER be a web application, regardless of any hacks you do to make it run inside a web browser. winforms 应用程序永远不会是一个 web 应用程序,无论你做了什么让它在 web 浏览器中运行的黑客。

an XBAP (WPF Browser Application) is also NOT a web application. XBAP(WPF 浏览器应用程序)也不是 Web 应用程序。 It's just a regular WPF client application that does not have it's own window.它只是一个普通的 WPF 客户端应用程序,没有自己的窗口。

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.如果您以正确的方式做事(即,维护关注点分离并将应用程序逻辑放在控制器或视图模型中,而不是大多数 winforms 开发人员通常习惯的实践背后的可怕代码),那么重用您的应用程序逻辑应该不难并创建一个新的应用程序(Web 或其他),同时保持数据访问和业务逻辑层的完整性。

In my limited experience with Visual WebGui , it is pretty cool technology.在我对Visual WebGui 的有限经验中,它是一项非常酷的技术。 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.简单来说,据我所知,您可以使用 Windows 窗体开发 IDE 创建一个符合 HTML5 的 ASP.NET 客户端/服务器 Web应用程序......不仅仅是一个网站或页面,外观和感觉非常像Windows 窗体桌面应用程序。 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.它通过在客户端将 Winforms 控件转换为 jquery 代码来实现这一点,并将大部分可执行代码存储在服务器端。

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.首先,要创建一个“漂亮”的网站,您需要重新考虑 Winforms 的布局,使其像 Web 一样,带有标题、侧边栏等。这是一种不同的范例,用户期望网站上有某些东西。 The good news is that this adjustment can often be done fairly easy by simply manipulating controls;好消息是,通过简单地操作控件,这种调整通常可以很容易地完成。 ie 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.另一个考虑因素是弹出对话框之类的事件在 Web 环境中的行为不同。 In Winforms program execution halts until the user clicks an "OK" button or something.在 Winforms 中程序执行停止,直到用户单击“确定”按钮或其他东西。 Within Visual WebGui, all the execution happens on the server side;在 Visual WebGui 中,所有的执行都发生在服务器端; 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.这可以通过为弹出框创建一个 Form.Close 处理程序来处理。 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. Visual WebGui 通常在模仿 Winforms 所见即所得的好处方面做得很好:对象通常出现在网页上与您将它们放置在环境中的位置非常接近。 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.尽管如此,它通常比用 CSS 或 div 对象繁琐地改变间距要容易得多。

I think this question is very similar to this one:我认为这个问题与这个问题非常相似:

Is it possible to convert a WinForm to a WebForm in .NET? 是否可以在 .NET 中将 WinForm 转换为 WebForm?

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.如前所述,在浏览器中“按原样”运行应用程序的唯一方法是使用一些 activex 控件,这需要 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.您可以使用一些工具将应用程序自动迁移到 Web,但总会涉及一些手动工作,这与从头构建应用程序作为 Web 应用程序不同。

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. Thinfinity VirtualUI 允许您通过向 C# 应用程序添加一小行代码来实现此目的,然后可以通过支持 HTML 的浏览器从任何操作系统和设备访问它。

https://www.cybelesoft.com/thinfinity/virtualui/web-integration-for-windows-apps/ https://www.cybelesoft.com/thinfinity/virtualui/web-integration-for-windows-apps/

I've used VWG but it's not really an option anymore.我使用过 VWG,但它不再是一个真正的选择。 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.此处未提及的一个选项是 WiseJ,这是一个专有框架,2022 年仍在积极开发和支持中。将 WinForms 应用程序转换为 WiseJ 相当简单,或者像 WinForms 一样开始使用 WiseJ。

They are located here: https://wisej.com它们位于此处: https://wisej.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM