4 Replies - 4277 Views - Last Post: 17 November 2011 - 09:17 AM Rate Topic: -----

#1 Recoil   User is offline

  • D.I.C Addict

Reputation: 51
  • View blog
  • Posts: 504
  • Joined: 28-June 08

Adding controls to child control on custom control

Posted 17 November 2011 - 07:43 AM

Private Sub myPanel_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded

        'myInnerContainer.Controls.Add(sender)

    End Sub



Here is the issue...I have a panel as the base of my custom control and I am adding other panels to it, along with a flow layout panel(myInnerContainer). I know the code above isn't going to work because when I try to add the regular panels to the main control, they will attempt to be added to the flow layout panel (myInnerContainer), and cause a circular error. I have tried various forms of

If sender.type = Button...



but intellisense doesn't display anything which leads me in the correct direction for adding only the buttons to the flow layout panel (myInnerContainer). Google has failed because nothing I have searched for helps...and I am probably searching for the wrong thing. Like always I believe I am over-thinking how to resolve this issue, and could use a point in the right direction. Thanks for any help I can get.

Is This A Good Question/Topic? 0
  • +

Replies To: Adding controls to child control on custom control

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14088
  • View blog
  • Posts: 56,440
  • Joined: 12-June 08

Re: Adding controls to child control on custom control

Posted 17 November 2011 - 08:19 AM

What's the issue? Generically I just whipped this up on a button click event inside a panel called panel1.

'-- some event that you want to trigger this adding of controls
Dim foo As New Panel '-- create the gui control.
foo.Name = "myPanel" '-- you should uniquely label your controls for reference later
foo.BackColor = Color.Green '-- this is just to show it's been there
foo.Dock = DockStyle.Left '-- want to dock it to the left of my existing panel
foo.Width = 40 '-- sure.. make the width 40
Panel1.Controls.Add(foo) '-- add it to your existing panel1
'-- end of that some event.


Was This Post Helpful? 1
  • +
  • -

#3 Recoil   User is offline

  • D.I.C Addict

Reputation: 51
  • View blog
  • Posts: 504
  • Joined: 28-June 08

Re: Adding controls to child control on custom control

Posted 17 November 2011 - 08:50 AM

It is not the adding controls on the main panel of the custom control...I have that down, and it is adding the additional panels on a CreatControls sub.

I have a test form, with the custom control on it, along with a button. On the button's click event, I am declaring new buttons to add to the flow layout panel, which is inside the custom control...this is simulating how my main program is creating controls to send to the custom control. However, the flow layout panel isn't accessible from the test form, it is only accessible from the custom controls code.

So, when I am adding the newly created buttons on the test form, it isn't adding them to the inner flow layout panel, it is adding them to the main panel of the custom control.

In my current program I already have something similar working where I send buttons to the flow layout panel that is inside the main control...but it is all created in the current program where I am adding controls to controls, and not in the actual control itself. Due to needing additional features from the custom control, I have to upgrade the custom control to encapsulate all of it's child controls, and have access to them by being able to send in things like buttons to display in the flow layout panel, which is then going to a bunch of additional stuff...

Look at the top right control here...
Posted Image

...that consists of 3 controls, a main panel, an inner panel to hide scrollbars of the child control-->, and a flow layout panel. These are created within the code of the main program. Now I have to add the option to sort the lists of buttons within the flow layout panel and a few more things...which is going to require 4 more panels. Due to this being the same features more than once for several forms it only makes sense to create a control. Since I have failed horribly at getting matching scrollbars to work with this, I am adding a paging-type control instead, that will allow previous or next pages of controls. That is it in a nutshell. If it were not for the needing to sort, or the need for scrollbars/controlpages, then I would not need to worry with this...yet can determine a better way of going about this.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14088
  • View blog
  • Posts: 56,440
  • Joined: 12-June 08

Re: Adding controls to child control on custom control

Posted 17 November 2011 - 09:04 AM

Okay you lost me. Adding controls to any collection is the same - be it a panel on the main form, the main form itself, flow controls, etc. Every collection has the '.controls' collection in it. You just need to make sure your work is right.
Was This Post Helpful? 1
  • +
  • -

#5 Recoil   User is offline

  • D.I.C Addict

Reputation: 51
  • View blog
  • Posts: 504
  • Joined: 28-June 08

Re: Adding controls to child control on custom control

Posted 17 November 2011 - 09:17 AM

Okay, I kind of follow now. I have resolved this by creating another public sub "addChildControl ByVal sender..." on the custom control, that adds the sender to the flow layout panel inside it. It is working now, so on the test form when I click the button on it, it adds a new button into the flow layout panel, inside the custom control.

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1