开发者

How to create custom component in form in C# 2010?

开发者 https://www.devze.com 2023-03-07 21:57 出处:网络
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 co

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

  1. 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.

  2. 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.

  3. 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.

  4. Build the project: On the Build menu, click Build Solution.

Ref.

0

精彩评论

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