且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Web窗体到Windows窗体

更新时间:2023-02-05 18:20:55

Win Forms编程使用完全不同的Web表单方法。



使用Web表单,客户端代码(HTML /浏览器页面)与服务器端(应用程序代码)分离,因此ASP.Net使用查看状态和会话状态来管理应用程序状态。实施Web园艺会使此问题变得更糟,因为您无法保证为每个后续请求获取相同的过程。



这不是Win Forms的问题。表单附加到应用程序代码并作为单个进程运行。因此,不需要视图状态和会话状态。



要在Win Forms应用程序中保留信息,您只需将对象分配给可在需要时检索的引用。



在Web窗体中,每个帖子都会构建页面。使用Win Forms,表单只构造一次,动作通常是表单上的事件。



视图状态的目的是保持Web表单的状态在回发后重建页面时因为使用Win Forms只有一个表单的实例在关闭之前一直存在,所以不需要查看状态。



如何在其他方面存在很多差异你也应该接近设计。
Win Forms programming uses a completely different approach to Web Forms.

With web forms the client code (HTML/Browser page) is detached from the Server Side (Application code) so ASP.Net uses the View State and Session State to manage application state. This problem is made worse by implementing Web Gardening as you cannot guarantee to get the same process for each subsequent request.

This is not an issue with Win Forms. The Form is attached to the application code and runs as a single process. So no view state and no session state are required.

To persist information in a Win Forms application you need simply assign the object to a reference which can be retrieved when required.

In Web Forms the page is constructed with every post back. With Win Forms the form is only constructed once and actions are generally an event on the form.

The purpose of the View State is to persist the state of the Web Form when the page is reconstructed after a post back. Because with Win Forms there is only one instance of the form which persists until closed, there is no need for a View State.

There are lots of other differences in how you should approach to design too.