How to create custom component in form in C# 2010?
I want to create a custom component in开发者_JAVA百科 C# and the custom component is going to act as a gauge and consist of a panel with some icons inside it. Is there a way to create a custom panel component with all of these items inside it and then interact with it all as one component?
It is called a Usercontrol (or composite control):
How to add and create a Usercontrol in Visual Studio 2008 (Says 2008, but everything should also apply to 2010)
Walkthrough: Authoring a Composite Control with Visual C#
See also: Walkthrough: Creating a Windows Forms User Control that Supports Lookup Databinding
To create the .NET user control
Create a Visual C# Windows Forms Control Library project named WindowsFormsControlLibrary1: On the File menu, click New and then click Project. In the Visual C# folder, select Windows Forms Control Library. Accept the WindowsFormsControlLibrary1 project name by clicking OK. By default, the name of the .NET control will be UserControl1.
Add child controls to UserControl1: In the Toolbox, open the All Windows Forms list. Drag a Button control to the UserControl1 design surface. Also add a TextBox control.
In Solution Explorer, double-click UserControl1.Designer.cs to open it for editing. Change the declarations of the TextBox and the Button from private to public.
Build the project: On the Build menu, click Build Solution.
Ref.
精彩评论