Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:29:57+00:00 2026-06-11T18:29:57+00:00

InitializeComponent sets up the components on the form, however for a Usercontrol that I

  • 0

InitializeComponent sets up the components on the form, however for a Usercontrol that I have created it calls the default constructor but I want to call my own constructor (with parameters) on the usercontrol. The boilerplate code says don’t edit the contents, so what is the best way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:29:58+00:00Added an answer on June 11, 2026 at 6:29 pm

    You need to create a TypeConverter class, and decorate your UserControl with a TypeConverterAttribute(typeof(MyTypeConverter)). The type converter will tell Visual Studio how to create your types – allowing you to control what gets put in the InitializeComponent.
    You can go REALLY deep, and actually write a custom CodeDomSerializer, in which you can then write out ANY C# code you want – I used this technique to force the InitializeComponent method to resolve all Forms controls from Castle Windsor! That works really well…

    Anyway…

    You’ll notice MS already uses this technique for types like this:

    this.treeView1 = new System.Windows.Forms.TreeView();
    this.treeView1.Location = new System.Drawing.Point(72, 104);
    this.treeView1.Name = "treeView1";
    this.treeView1.Nodes.AddRange(
    new System.Windows.Forms.TreeNode[] {
      new System.Windows.Forms.TreeNode("Node0"),
      new System.Windows.Forms.TreeNode("Node1")});
    

    Basically – in your TypeConverter, you override the ‘ConverterTo’ method, and return a new InstanceDescriptor, which will describe to the WinForms designer, HOW to instantiate your type (what constructor to use, and what arguments to pass).

    You can find heaps more information here (including basic implementation):
    http://msdn.microsoft.com/en-us/library/ms973818.aspx

    InitializeComponent is REALLY powerful, once you get your head around all the extensibility points.
    Happy coding!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created some UserControl. Here is its constructor: public ZoomableChart() { InitializeComponent(); this.mainChart =
We have a project that sets the DataSource of a combobox, but allows users
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
In a Windows Form Application, I have a ComboBox1 which gets initialized in InitializeComponent()
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a custom usercontrol that does a little animation on a DispatcherTimer tick,
I create a constructor as follow Form1(array<System::String ^> ^args) //HW5 { InitializeComponent(); // //TODO:
I am tring to create a simple UserControl that contains a set of RadioButtons
My problem is this, I have a UC called profile that contains another UC
I have the following Code : public GUIWevbDav() { InitializeComponent(); } private void Form1_Load(object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.