开发者

Is Possible to convert the controls to Component or component to control in winforms?

Is Possible to convert the controls to Component or component to control in winforms?And is possible to make transparen开发者_开发问答t the button in winforms?


There is a huge difference between Component and Control. Component is a very simple class, it has 3 members for design time support, 6 members for runtime support, that's all. You can drop one on a form so that its properties can be edited. Anything useful it does at runtime must be implemented by the component itself, there is no help from Windows Forms.

Control extends Component by adding members that allows it to have a well defined runtime behavior as well, most notably by wrapping a native Windows window. You can see it and click it. Big job, that takes hundreds of members, although most of them are not visible in the designer.

Turning a Control into a Component but still retaining Control characteristics is possible. The ToolStripItem does that. However, it requires an enormous amount of code since you have to replace every feature that a Windows window provides. That's hard, even for Microsoft, the ToolStripItem classes have a lot of bugz. The only benefit you get from this is that you can avoid allocating a window handle. Which can be compelling at times, windows are expensive objects and can make your code run slow. And you're stuck with the way a window works, poor transparency support for example.

Supporting transparency with a Component is not an issue, it is just multiple layers of paint on top of each other. You have however have to provide everything else a Control does.

Getting to the point, this has already been done. It is the exact model for WPF. A WPF app (usually) has only one native window handle. Everything else is drawn inside of it by the WPF rendering engine. It therefore has no trouble supporting transparency effects. Any many other bells and whistles, like rotated controls, that you can't get a native window to do. Or a browser.

If you want to stick with WF, explain in detail what kind of transparency effect you need. There are many ways to get one, it just depends on what you're trying to do. Fwiw, a good question at StackOverflow is about as long as a good answer.


You can host a Component in any object that implements the IContainer interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜