tags:

views:

101

answers:

3

Is Possible to convert the controls to Component or component to control in winforms?And is possible to make transparent the button in winforms?

A: 

On the button transparency, here's a thread with a possible answer for you:

http://stackoverflow.com/questions/1086621/drawing-a-transparent-button-in-c-winforms

Tony
A: 

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

GxG
Sorry,can you explain in detail?
Harikrishna
Components are usually storage space for common language runtime things... they are usually used for interlanguage migration. for example sending the value of a variable from a C# application to a Java application(they both use CLR when running so a Component is basically the only way to do this) if you need to transfer a control it can be a little difficult because rendering a control is done before converting to CLR
GxG
Is toolstripbutton placed in the toolstrip is component?
Harikrishna
i don't think so... it's a child control of the toolstrip
GxG
+3  A: 

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.

Hans Passant
@nobugz Sir,I have need of that becauseI have made one function named SetControls(control controlName) which only takes control as a argument.And I want to pass the toolstripbutton which is in the tooltipcontainer.Function SetControls() consider toolstripContainer as contol but does not consider toolstripbutton as control and there is error if I pass the toolstripbutton as control.So what shoud I do? I have post this question also individually.
Harikrishna
I already advised you to make another overload of your SetControls that takes a ToolStripItem argument.
Hans Passant
@nobugz Any other solution of it,sir ?
Harikrishna
@nobugz is ComponentConverter will work ? OR can toolstripitem can be convert to control?
Harikrishna
No. You're all over the place with this question, I thought this was about transparency. I don't think I can help you.
Hans Passant