简体   繁体   English

从控件继承的建议

[英]Suggestions for Inheriting from a control

I am planning to write a control that inherits from a third party ActiveX control. 我打算编写一个从第三方ActiveX控件继承的控件。 The requirements are: 要求是:

1) It should be able to be added from the toolbox in Visual Studio 1)应该可以从Visual Studio的工具箱中添加它

2) It should be able to hide all the base class members and only provide access to the members from the derived class. 2)它应该能够隐藏所有基类成员,并且仅提供对派生类中成员的访问。 (the derived class will provide several custom events and functions) (派生类将提供几个自定义事件和函数)

One solution is to not use inheritance at all, have a class that would declare the ActiveX control private and initialize it dynamically at run time. 一种解决方案是根本不使用继承,而要拥有一个将ActiveX控件声明为私有并在运行时动态初始化的类。 However, this does not satisfy my first requirement. 但是,这不能满足我的第一个要求。 Is there a way I could achieve the functionality I want. 有没有一种方法可以实现我想要的功能。

PS: I do not have access to the source code of this control PS:我无权访问此控件的源代码

You can make your solution (composition) work by using a simple Panel control as the containing class. 您可以通过使用简单的Panel控件作为包含类来使您的解决方案(组合)正常工作。

There is no way to (really/effectively) hide base class members when using inheritance. 使用继承时,无法(真正/有效地)隐藏基类成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM