如何使用VBA将按钮的图片更改为嵌入式默认图像之一? [英] How could I use VBA to change a button's picture to one of the embedded default images?

查看:500
本文介绍了如何使用VBA将按钮的图片更改为嵌入式默认图像之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击它时,我试图获取一个按钮,将其从向左箭头"更改为向右箭头",但是我不确定如何通过VBA分配图像.我尝试了Me!btnCollapseUnscheduled.Picture = "Arrow Left",但是这样会收到错误消息.

I'm trying to get a button to change from the "Arrow Left" to "Arrow Right" picture when I click it, but I'm not sure how to assign the images through VBA. I tried Me!btnCollapseUnscheduled.Picture = "Arrow Left", but I get an error message this way.

推荐答案

在Access 2010或更高版本中,可以将图像存储在 MSysResources 系统表中.然后为命令按钮的图片类型属性选择共享,然后选择其中一个共享图像.

In Access 2010 or later, you can store images in the MSysResources system table. Then choose Shared for your command button's Picture Type property, and select one of those shared images.

然后,很容易在命令按钮的单击事件中在共享图像之间切换.我将命令按钮命名为"cmdArrow" ,并将共享图像命名为向左箭头" 向右箭头" ...

Afterward, it's easy to toggle between the shared images from the command buttons's click event. I named my command button "cmdArrow" and the shared images "Arrow Left" and "Arrow Right" ...

Option Compare Database
Option Explicit

Private Sub cmdArrow_Click()
    Dim strDirection As String

    If Me!cmdArrow.Picture Like "*Left" Then
        strDirection = "Right"
    Else
        strDirection = "Left"
    End If
    Me!cmdArrow.Picture = "Arrow " & strDirection
    Me!txtImage.Value = Me!cmdArrow.Picture
End Sub

Private Sub Form_Load()
    Me!txtImage.Value = Me!cmdArrow.Picture
End Sub

屏幕截图:

最大的挑战是将图像加载到 MSysResources 中.我创建了一个一次性表单,并添加了一个命令按钮.接下来,我选择 Embedded 作为按钮的 Picture Type 属性,并从可用选项中选择向左箭头.然后,我将图片类型嵌入式更改为共享,从而在 MSysResources 中添加了一行,并在其中添加了图像数据附件字段和名称字段中我命令按钮的名称.因此,我打开了表格,将 Name 更改为向左箭头" 并关闭了表格.注意除非在导航选项中启用显示系统对象" ,否则 MSysResources 在导航"窗格中将不可见.

The biggest challenge was loading the images into MSysResources. I created a throwaway form and added a command button. Next I chose Embedded as the button's Picture Type property and selected Arrow Left from the available choices. Then I changed Picture Type from Embedded to Shared, which added a row to MSysResources with the image data in an attachment field and my command button's name in the Name field. So I opened the table, changed Name to "Arrow Left" and closed the table. Note MSysResources will not be visible in the Navigation pane unless you enable "Show System Objects" in the Navigation Options.

我对向右箭头" 重复了这些步骤.听起来可能有些怪异,但这并不是一个很大的障碍.

I repeated those steps for "Arrow Right". It may sound fiddly, but it's not really a huge hurdle.

这篇关于如何使用VBA将按钮的图片更改为嵌入式默认图像之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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