删除WinForm控件的原始事件行为控件、原始、行为、事件

2023-09-07 16:32:55 作者:鹿死玫瑰海。

我想删除表单中的控件的原始事件的行为(类似设计模式)。 所以,当用户点击该按钮,我只希望捕获的事件。我不希望原来的按钮事件被解雇。这在某种程度上可能吗? 我要寻找一个通用的解决方案。因此,它应该与任何形式和形式中的任何控制权。

I would like to remove the original event behavior of controls within a form (similar to design mode). So, when the user clicks on the button, i only want to capture that event. I do not want the original button event to be fired. Is this somehow possible? I am looking for a generic solution. So it should work with any form and any control within the form.

原因:我写了一个表单验证规则设计。它使用反射来枚举所有表单类型的入口组件。然后,用户可以选择一个形式类型,设计者创建的形式,列举了控制和embedds在设计面板的形式。 点击控件,打开一个公式推设计师面板,用户现在可以创建一个公式推该控件并保存公式推到一个数据库。 当窗体,然后在正常的运行模式打开,它加载了验证formulars。

Reason: I wrote a form validation rules designer. It uses reflection to enumerate all form-types in the entry assembly. The user can then select a form type, the designer creates that form, enumerates the controls, and embedds the form in the designer panel. clicking on a control, opens a formular designer panel, and the user can now create a formular for that control and saves the formular to a DB. When the form is then opened in the normal "runtime" mode, it loads its validation formulars.

推荐答案

事件是不是其实在的WinForms设计师禁用。设计者执行通过反射的形式的构造函数,一切都在InitializeComponent()方法执行,包括事件订阅。无论这可能会导致问题,对照检查DesignMode属性或定制设计师($ P $启动例如pvents定时器)。该表格​​显示在顶部透明分层窗口,其中选择矩形并拖动手柄画下方。其中prevents问题,鼠标点击和键盘焦点。

Events are not in fact disabled in the Winforms designer. The designer executes the constructor of the form through Reflection, everything in the InitializeComponent() method executes, including the event subscriptions. Wherever this might cause a problem, the controls check the DesignMode property (prevents a Timer from starting for example) or by custom designers. The form is displayed underneath a transparent layered window on top of which the selection rectangle and drag handles are painted. Which prevents issues with mouse clicks and keyboard focus.

您可能应该看看这本杂志文章得到这个为你工作。

You probably ought to look at this magazine article to get this working for you.