Click here to Skip to main content
15,887,888 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is my very first post ever on any type of forum so please go easy on me...

I am trying to create a custom panel component that has buttons already embedded in it. I want to be able to select and edit the buttons from the properties menu like you would be able to do with a default button, also with the ability to change the number of buttons that are in the panel with a property. The problem I am running into is when trying to create this custom component I cant figure out how to have the buttons dynamically create themselves during design time(by selecting a number from the properties menu).

So the end game would be to have the ability to drag this panel component from the toolbox and when it hits the form it will have a preset number of buttons already in it, but have the option to change the number of buttons from a property.

I do not have any code written yet as I can not find a direction to head toward.

Any help or advice would be greatly appreciated!

Thank you!
Posted

1 solution

Hi,
there are different ways to solve this Problem. I prefer the following :

- You have a collection for the elements which should be variable created.
- You build a SUB Create_Elements and a SUB Dispose_Elements
- When you Change the property of your Control which defines the number a elements you also run the SUB Dispose_Elemets and after this the SUB Create_Elements
- inside the SUB Create_Elements you have the following Code :
VB
<pre lang="vb">
for i as integer = 1 to _Number_Elements
   Dim myControl as new Button  ' for Example a Button
   ' now you have to set also the properties for the Button as there are : Name, Text, Size, Location, Color and so on
   myControl.parent = Me 
   myCollection.add(myControl)
next


in the Sub Dispose_Elements your run through your Collection to dispose the elemets inside.

If would suggest that you first try to build up my Suggestion.
After that (with seeing your code) we could complete it ...

greetings
Ralf
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900