Is it wise to create composite controls?

后端 未结 4 1122
渐次进展
渐次进展 2021-01-06 17:31

I have this application that reuses a sort of idiom in a number of places. There\'s a TPanel, and on it are some labels and buttons. The purpose is to allow the user to sele

4条回答
  •  时光说笑
    2021-01-06 18:17

    A very pragmatic way to develop composite controls is to use TFrame as a base for it.

    That way, you can visually design your control, and either use events or inheritance

    There are a couple of things you need to watch but all in all it is a much easier process than coding everything by hand (like some of the other answers suggest).

    Things to watch for (not a complete list, but close):

    • don't forget the sprig
    • at design time (both in the TFrame and when putting the composite control on a design surface), sub-controls marked Visible=True are still visible. Two ways to solve this: Destroy those controls, or move them to an invisible region (Top/Left to minus values or to values bigger than Width/Height of the parent)
    • registering the TFrame descendent as a component where the TFrame descendent is also part of your project sometimes confues the IDE. Easy solution: call the TFrame descendent "TMyCustomControl", derive "TMyControl" from it, and register "TMyControl" as a component.

    As a bonus, you don't have to remove the bevel/border and caption from the TPanel.

提交回复
热议问题