Results 1 to 2 of 2

Thread: How can I add a control to a parent form, in design time, through a custom component?

  1. #1

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    How can I add a control to a parent form, in design time, through a custom component?

    I have create a custom component which changes some properties of it's parent form when placed in design time. But I also want this component, in design time again, to add some controls to it's parent form. I tried something like this code example below, but with no luck. The added control placed on the form, but I can't select it, just stands there!!! Any idea what exactly am I doing wrong? Thank you in advance!!!
    Code:
    Public Class MyCustomComponent
         Private _MyControl As New MyUserControl
         
         '...Rest of my code
         
         Private Sub OnPlace()
               '...Rest of my code
              _ParentForm.Controls.Add(_MyControl)
         End Sub
    
         Private Sub OnDispose()
               '...Rest of my code
              _MyControl.Dispose()
        End Sub
    
    End Class

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: How can I add a control to a parent form, in design time, through a custom compon

    Suppose you drag a button onto a Form, and code its Click event to show a message box. In the Designer, you can do all sorts of things to the button, like dragging it around, setting its properties in the Properties window and so on. You can click on it too. But it doesn't perform your event code - it doesn't show a message box. And if you double-click it, Visual Studio will take you to the form's code, something that fortunately doesn't happen at run time.

    Suppose you make a UserControl with a button on it, and drag an instance of it onto a form. What you see is not a real user control but a picture of it. You can drag the UC around and change its properties in the Forms Designer. But you can't do these things to the child button (unlike in the UserControl Designer). The Forms Designer doesn't even know that there's a button in the picture.

    Creating a Component to insert a button into the host form, for example in the Host.Set property is similar. The Form Designer will paint a picture of the button (the component itself remaining invisible) but apart from that the designer doesn't even know it's there. Yet the button is functional at run time.

    To sum up, the design time behaviour is governed by the Designer, and the run time behaviour is governed by your own code. You can of course customize the designer in some respects; I think by now you know more about that than I do.

    BB

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width