将随机图像添加到标签

发布于 2024-10-31 18:37:34 字数 116 浏览 1 评论 0原文

用户窗体 2 = 36 个按钮(btn1 至 btn36) 每个按钮上都有一个图像。 当我单击“ADD”按钮时,我希望按钮上的三个随机图像显示在用户窗体 1 的三个标签中,其中显示“随机图像 1”。

UserForm 2 = 36 buttons (btn1 thru btn36) Each button has an image on it.
When I click the "ADD" button I would like for three randon images that are on the buttons to show up in UserForm 1 three lables where it says Random Image 1.

Right now when I click the "ADD" button, it brings up UserForm1.  When I click "OK" on UserForm1 I would like to state which three buttons were inserted into UserForm1 on a spreadsheet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2024-11-07 18:37:34

要选择随机按钮图像,您需要使用表单上的 Me.Controls 集合。例如:

Dim cCont As Control
For Each cCont In Me.Controls
    'DO STUFF HERE
Next cCont

如果您在变量 cCont 上放置一个监视,您可以看到每个控件具有的所有属性。首先,您必须过滤掉按钮控件。然后,您必须查看该按钮的图像属性以获取它并在第二个表单上进行设置。

最后,要引入随机元素,只需使用 Rand() 函数即可。这将返回 0 到 1 之间的随机数。如果将其乘以 Me.Controls 中的控件数量,并将其舍入为整数,您将获得一个随机控件。只需确保您索引的控件是一个按钮,并且您可以使用该按钮的图像作为随机图像之一。

To choose a random button image you'll need to use the collection Me.Controls on the form. For example:

Dim cCont As Control
For Each cCont In Me.Controls
    'DO STUFF HERE
Next cCont

If you put a watch on the variable cCont, you can see all the properties each control has. First, you will have to filter out the controls that are buttons. You will then have to look at the image property for that button to grab it and set on the second form.

Finally, to introduce a random element, just use the Rand() function. This will return a random number between 0 and 1. If you multiply this by the number of controls in Me.Controls, and round it to an integer, you will get a random control. Just make sure that the control you indexed is a button, and you can use that button's image as one of the random images.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文