简体   繁体   中英

Using a usercontrol in c#

I have created a custom UserControl that includes several text boxes and radio buttons. I want to place this UserControl onto several panels that I'm using for a wizard.

How can I actually use this UserControl? ie I want to drag and drop it onto each of my panels? How do I do this?

Or is there a container that I can drop onto the panel and then set it to my user control?

Ensure the UserControl class is part of your project or is inside a project that's included with your Solution. After you build your program, your user control will appear at the top of the toolbox. Drag it onto a form or panel, as desired.

If you don't see the control appear then you may have a setting wrong. Tools + Options, Windows Forms Designer, General. Ensure that "Automatically Populate Toolbox" is set to True.

Press "F6" (edit: or any other key which rebuilds the project - "F6" is standard in Vs2010) and it will appear in the Toolbox in the designer, then you can drag and drop it. Note that always when you change something at a UserControl you first have to rebuld the project for the changes to take effect.

To do it programmatically:

UserControl myUI = new UserControl();
/// Blah blah
this.Controls.Add(myUI);

Actually when make a userControl, save it and Run your application that control should appear on top of Toolbar...

喜欢这张图片

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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