将随机图像添加到标签
用户窗体 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要选择随机按钮图像,您需要使用表单上的 Me.Controls 集合。例如:
如果您在变量 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:
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.