Windows窗体中PageLoad的替代方法 [英] Alternative to PageLoad in Windows Forms
问题描述
我在 Windows表单表单上有很多事件.我有一个反馈标签,我必须写feedbaxk.Text =";在每个事件开始时.
在 ASP.NET 中,我一直只在其中写入一次每次回发都会触发的page_load
事件,但是Form Load仅触发一次.
我尝试搜索问题的标题,并发现以下两个最接近的答案:
-
在.NET 和 .看完这些之后,我认为有可能
- 我可以在Form_Load的末尾以win-form的形式获得所有事件的列表(此后,我不再添加任何事件).然后为所有事件添加一些通用功能(例如更改标签文本).
- 我也许能够从父事件继承所有事件,并在该事件中添加所需的功能,然后向每个事件添加(覆盖)特定的功能.
解决方案这取决于您要处理的任何特定事件,因为在您的窗口中,您可以具有调整大小",单击",移动"等事件.已经提到了ASP.NET,似乎您希望通过单击某些按钮来处理此问题.
您可以尝试覆盖WndProc并处理 WM_COMMAND 消息.如果您想通过某些特定的按钮来处理此问题,那么我会说您要为每个按钮进行处理.
I have many events on a Windows Forms form. I have a feedback label, and I have to write feedbaxk.Text=""; at the beginning of each event.
In ASP.NET, I have been using to write it only once in the
page_load
event which is fired on every postback, but Form Load fires only once.I have tried to search with the title of my question and found following two closest answers:
WinForms equivalent of ASP.NET page load event (PC Review)
There is some relevant material, but I could not get satisfying answer from these and many more.
How it can be detected in Windows Forms that an event is going to be fired?
Update: By googling it another way, I found a close link which is linked with another links, Find all event handlers for a Windows Forms control in .NET and Is it possible to "steal" an event handler from one control and give it to another?. After viewing these I think it is possible if
- I could get list of all events in a win-form say at the end of Form_Load (after that I don't add any more events). Then add a little common functionality (say changing a label text) to all events.
- I might be able to inherit all of my events from a parent one and add my desired functionality in that event and then add (override) specific functionality to each event.
解决方案It depends on any specific events you want to handle, because in your window you can have events for Resize, Click, Move, etc. Looking at the point you have raised with reference to ASP.NET, it seems you want to handle this on some button click.
You can try to override WndProc and handle the WM_COMMAND message. If you want to handle this on some specific button click then I would say you handle this for each button.
这篇关于Windows窗体中PageLoad的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!