C # WindowsForms UserControl Controls Support

What I'm looking for is designer support of the same type for controls inside usercontrol. i.e. - resizing the text field by moving the label that are inside the UserControl after placeing in the UserControl on the form

What could I do...

  • create usercontrol
  • use the constructor to add controls to it.
  • create a new form window
  • add usercontrol to toolbar
  • drag the control onto the form

where am i stuck ...

  • edit usercontrols controls. IE - the ability to resize the text field inside the usercontrol using the constructor.

I found a similar question on a stack that was never answered. So if I'm too vague, you can follow this link https://stackoverflow.com/questions/10359772/example-make-constituent-controls-in-a-usercontrol-editable .

Thanks.

+4
source share
1 answer

After reading Nikita's comment, I managed to find a Microsoft support page for creating a custom designer for controls.

Here's a quote if you're interested in how development-time support works.

However, development-time support for components in the .NET Framework is not solely determined by a development tool such as Microsoft Visual Studio .NET. Rather, the development environment supports extending and defining development-time behavior by class, such as designers, who provide support for component development time. Support for extensible and custom development mode behavior is an integrated part of the .NET Framework. Tools such as Visual Studio .NET also provide a number of development-time services that designers can use.

This is a web page if you want to continue reading and viewing samples from Microsoft

Improved development time support

Everything seems complicated when you are just starting to learn it, this is a sample working code for UserControl with a PictureBox and an inscription on it. Both controls can be edited at design time, i.e. resize and move, as well as open all your events and properties if you click on them.

You will need to add a link to System.Design, which can only be referenced if you have not targeted ".Net client profile". You can change your target profile in the "Accessories / Applied / TargetFramework" section.

Add the usercontrol project to the project and add a class to handle its constructor. Double-click the usercontrol element, and then add a shortcut and a window with an image on the toolbar.

Then open the class you create to be its designer. Add this ...

using System.Windows.Forms; using System.Windows.Forms.Design; public override void Initialize(IComponent component) { base.Initialize(component); if (this.Control is MyUserControl) // replace this with your usercontrol type { // cast this.Control to you type of usercontrol to get at it's // controls easier var i = this.Control as MyUserControl; // replace *** this.EnableDesignMode(i.label1, "unique_name1"); this.EnableDesignMode(i.pictureBox1, "unique_name2"); } } 
+3
source

All Articles