如何将文本框和标签添加到用户窗体中的框架?

How to add text boxes and labels to a frame within a userform?

我正在尝试创建一个用户表单。在 select 产品代码并输入数量后,我希望此代码出现在框架中的次数与输入的数量一样多,并且我希望创建一个 TextBox 以输入到期日期。你可以看到我在瞄准什么图片。

This is the main structure of my user form. It must look like this after adding the product code and quantity.

您的描述没有多大意义,但要回答您的问题 问题:
如何在用户表单中的框架中添加文本框和标签?

  • 先画框

  • 绘制框架的控件"on top"。

  • 您可以通过单击其他地方确认控件已附加到框架,然后单击控件,并验证框架是否也被自动选中。

您的目标雄心勃勃,一点也不简单。我可以给你一些提示,但你必须完成它。

因此,为了回答您最初的问题,您可以这样在框架中定义控件:

Dim tb as Object, lb as Object
Set tb = Frame1.Controls.Add("forms.textbox.1")
Set lb = Frame1.Controls.Add("forms.label.1")
lb.caption = <the recently entered product code>
lb.top = <you need to keep track of position of next entry>
lb.left = 50            ' from the left border of frame1
tb.top = lb.top
tb.left = lb.left + 100

然后您必须将文本框存储在一个集合(或数组,如您所愿)中以处理输入的到期日期。

很快。请注意,您必须实现更多功能才能使您的应用程序健壮可靠。