Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VS question about the auto generated InitializeComponent() method

VS question about the auto generated InitializeComponent() method

Scheduled Pinned Locked Moved C#
questionvisual-studiocsharptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akkram
    wrote on last edited by
    #1

    Hi. I have a question regarding the auto-generated InitializeComponent() code when using visual studio. For example, if I have a form and a user control. Now, when I drag the user-control onto the form VS automatically instanciates the user-control inside the InitializeComponent() method. But say I have a property in the user-control I want to set through it's constructor, ie. passing some parameter when istansiating the user-control. How can I do this without editing the InitializeComponent() in the code-editor?

    U 1 Reply Last reply
    0
    • A akkram

      Hi. I have a question regarding the auto-generated InitializeComponent() code when using visual studio. For example, if I have a form and a user control. Now, when I drag the user-control onto the form VS automatically instanciates the user-control inside the InitializeComponent() method. But say I have a property in the user-control I want to set through it's constructor, ie. passing some parameter when istansiating the user-control. How can I do this without editing the InitializeComponent() in the code-editor?

      U Offline
      U Offline
      Urs Enzler
      wrote on last edited by
      #2

      To use your UserControl within the VS Designer it has to have a default constructor. I see two solutions to your problem: 1) let everything the way it is now and add a property set what you have to set. 2) Add your UserControl dynamically (with the constructor with your parameters) in the Load event of your Form. If you want designer support then I'd suggest you use solution 1. The property value can be set either in the designer (if it is a constant value) or somewhere in the code. Happy coding

      -^-^-^-^-^-^-^-^-^-^-^- no code is free of bugs

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups