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. constraining an ExtenderProvider ... Winform Component

constraining an ExtenderProvider ... Winform Component

Scheduled Pinned Locked Moved C#
designhelpcomdockertutorial
3 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.
  • B Offline
    B Offline
    BillWoodruff
    wrote on last edited by
    #1

    My intention is to publish, here, a tutorial on extending 'Form with a Component in what I hope will be a novel, and useful, way. As you may know, a component that implements IExtenderProvider (see: [^]) can be drag-dropped into the component UI area of the Form, and will be exposed at design-time by the type of object it extends. Note that the MSDN sample implementation here: [^] ... as so often, brain-damaged with crap code ... is a Control, not a Component. Okay, now I have my Component working, extending 'Form; I have solved the problem of detecting the Component instance's run-time Container using reflection (the only way to do it !). Necessary Properties are now exposed in the design-time 'PropertyGrid. Depending on the user's design-time choice, one of four possible "flavors" of another Form are created. All this is working. The issue now ... is that I want to constrain the number of auxiliary Forms created to only one of each of the four "flavors." AFAIK, this cannot occur at design-time in the Component's code: there aren't any Events, and the 'InitializeComponent method does not get called. So, which do you think is better: handle preventing duplicates in a special static Class, or handle them in the Form 'Load Event when I enumerate the Components, and take actio based on the user-set Properties ? thanks, Bill

    «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

    L 1 Reply Last reply
    0
    • B BillWoodruff

      My intention is to publish, here, a tutorial on extending 'Form with a Component in what I hope will be a novel, and useful, way. As you may know, a component that implements IExtenderProvider (see: [^]) can be drag-dropped into the component UI area of the Form, and will be exposed at design-time by the type of object it extends. Note that the MSDN sample implementation here: [^] ... as so often, brain-damaged with crap code ... is a Control, not a Component. Okay, now I have my Component working, extending 'Form; I have solved the problem of detecting the Component instance's run-time Container using reflection (the only way to do it !). Necessary Properties are now exposed in the design-time 'PropertyGrid. Depending on the user's design-time choice, one of four possible "flavors" of another Form are created. All this is working. The issue now ... is that I want to constrain the number of auxiliary Forms created to only one of each of the four "flavors." AFAIK, this cannot occur at design-time in the Component's code: there aren't any Events, and the 'InitializeComponent method does not get called. So, which do you think is better: handle preventing duplicates in a special static Class, or handle them in the Form 'Load Event when I enumerate the Components, and take actio based on the user-set Properties ? thanks, Bill

      «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Sounds like a "business rule" being baked in; maybe it should be a run-time option; which means at "load time"; preferably with a message if the rules are violated.

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      B 1 Reply Last reply
      0
      • L Lost User

        Sounds like a "business rule" being baked in; maybe it should be a run-time option; which means at "load time"; preferably with a message if the rules are violated.

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        B Offline
        B Offline
        BillWoodruff
        wrote on last edited by
        #3

        Thanks, Gerry, I like the idea of a run-time warning; but, I am curious how, in general, one can detect the drag-drop of a Component on a Form at design-time. It appears that's impossible. This is the code I use to find the custom Extender Provider using the Type of the Container Form:

        public IEnumerable EnumerateComponents(Type formtype, string targetname)
        {
        return formtype.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
        .Where(finfo =>
        finfo != null
        && typeof(IExtenderProvider).IsAssignableFrom(finfo.FieldType)
        && finfo.FieldType.Name == targetname);
        }

        cheers, Bill

        «Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot

        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