如何在设计时使用动态添加按钮创建自定义面板组件vb.net [英] How to create a custom panel component with dynamically added buttons at design time vb.net

查看:217
本文介绍了如何在设计时使用动态添加按钮创建自定义面板组件vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在任何类型的论坛上的第一篇文章,所以请放轻松我...



我正在尝试创建一个自定义面板组件已经嵌入了按钮。我希望能够从属性菜单中选择和编辑按钮,就像您可以使用默认按钮一样,还可以使用属性更改面板中按钮的数量。我遇到的问题是在尝试创建这个自定义组件时,我无法弄清楚如何在设计时动态创建按钮(通过从属性菜单中选择一个数字)。



因此,最终游戏将能够从工具箱中拖动此面板组件,当它到达表单时,它将具有预设数量的按钮它,但可以选择更改属性中的按钮数量。



我还没有写任何代码,因为我无法找到指示方向。



非常感谢任何帮助或建议!



谢谢!

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!

推荐答案



有不同的方法来解决这个问题。我更喜欢以下内容:



- 你有一个应该是变量创建的元素的集合。

- 你构建一个SUB Create_Elements和SUB Dispose_Elements

- 当您更改控件的属性时,您还可以运行SUB Dispose_Elemets以及之后的SUB Create_Elements

- 在SUB内部Create_Elements您有以下代码:
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 :
<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





在Sub Dispose_Elements中你通过你的收藏品来处理内部的元素。



如果建议你首先尝试建立我的建议。

之后(看到你的代码)我们可以完成它...



问候

拉尔夫



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


这篇关于如何在设计时使用动态添加按钮创建自定义面板组件vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆