5

I have several forms in a .net windows app that have a common set of textboxes and other user input controls,each form has the same look and feel, but each form needs to load and save to different database tables.

Would it be better to place the controls on a base form, and inherit from it or to create a user control to drop on each form?

4

4 回答 4

1

I usually prefer UserControls as they are more flexible - you can use them in the context of a form, or in any other visual context to display or modify data. I've had several cases where I had to change my UI design from a separate dialog to edit something to an inline control inside the main form or something like that.

Other than that, I'd say it's a matter of taste.

于 2008-10-12T18:20:00.430 回答
0

It depends. Composite model (using User Control) is cleaner, but the control cannot be aware of the calling form, so you have to pass the logic in as events. That sometimes can lead to duplicate logic.

With inheritance, you can implement common code at the base class with some override at the subclass form and implement flexible interplay. But that requires all implementers of the subclass to be aware of the base class source code, which can get chaotic.

于 2008-10-12T18:20:20.167 回答
0

取决于其更简单使用与事件相关的用户控件背后的逻辑。如果有共同的任务,您可以使用基类 Server Control。

于 2012-03-05T13:42:38.033 回答
0

我根据情况使用这两种方法。如果您有一块功能性的 LOGIC 想要直接放入未修改的表单中,那么我认为 UserControls 是合适的。但是,如果您只是想在多个表单中复制和扩展一个通用 UI,那么视觉继承可能是更好的选择。

于 2008-10-12T20:10:26.027 回答