External images
We can insert external images in all ribbon’s controls that allow the use of the attributes image and getImage. We use the getImage only when we need to select images at runtime; if not, we use the attribute image.
Montaribbons has a folder named imagens and there you can find as example 2 files: avel.gif and feed.png, that are used at the example ribbon rblimages.
When you are creating your ribbon, copy your images to the folder imagens of Montaribbons. You should then, copy them to the folder images of your project.
Create the folder images, at the same place of the application – that makes programming easier and allow us to use the relative path with the property CurrentProject.Path.
For the atribute image work, its necessary the use of the atribute loadimage os the tag CustomUI, that has the function of loading images fncLoadImage.
Check below, the atribute loadimage in the tag customUI:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="fncRibbon" loadImage="fncLoadImage">
... <button id = "bt1" label = "Feed" image="feed.png" size="large" onAction = "fncOnAction" /> ...
</customUI>
Everytime the atribute image is used, it will use the function fncLoadImage
See the function fncLoadImage:
Public Sub fncLoadImage(imageId As String, ByRef Image) On Error GoTo fError Dim strPath As String strPath = CurrentProject.Path & "\images\" If InStr(imageId, ".png") > 0 Or InStr(imageId, ".ico") > 0 Then Set Image = LoadImage(strPath & imageId) Else Set Image = LoadPicture(strPath & imageId) End If fError_Exit: Exit Sub fError: Select Case Err.Number Case 2220 MsgBox "Image " & imageId & _
" not found on the path ...", vbInformation, "Warn" Case Else MsgBox "Erro: " & Err.Number & _
vbCrLf & Err.Description, vbCritical, "Warn", _ Err.HelpFile, Err.HelpContext End Select Resume fError_Exit: End Sub
The argument imageld of the function has the name of the image of the attribute image of a control. This name must be the same as the image stored at the folder images. The argument image of the function, then, loads the image of the folder, on the control of the ribbon.
Images GIF, JPEG and BMP are accepted directly on the controls (button, gallery...) of the ribbon, using the method LoadPicture of the Access. Images PNG and ICO must be turned into BMP to be loaded. This can be done by the function LoadImage, which uses APIs of the Windows to do it. MontaRibbons exports for your project these APIs in a module named mod_picture.
Check the complete XML code of a Ribbon, using two buttons that load the images from the folder imagens of MontaRibbons:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="fncRibbon" loadImage="fncLoadImage">
<ribbon startFromScratch="true">
<tabs>
<tab id = "tab1" label = "Main" >
<group id = "gr1" label = "Buttons with external images">
<!-- to load the PNG file we use the function LoadImage -->
<button
id = "bt1"
label = "Feed"
image="feed.png"
size="large"
onAction = "fncOnAction"
/>
<!-- To load the GIF file we use the function LoadPicture of the Access -->
<button
id = "bt2"
label = "Avelino"
image="avel.gif" size="large" onAction = "fncOnAction" /> </group> </tab> </tabs> </ribbon> </customUI>
As result we got the ribbon:
As I said, we can load our images using the atribute getImage. This option is used when we need to change an image at runtime. We will use as example the same XML above, just changing the image attribute for the getimage attribute. The attribute getimage do not depends on the attribute loadimage of the tag customUI.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="fncRibbon">
<ribbon startFromScratch="true">
<tabs>
<tab id = "tab1" label = "Main" >
<group id = "gr1" label = "Buttons with external images">
<!-- Images are defined by the function fncGetImage -->
<button
id = "bt1"
label = "Feed"
getImage="fncGetImage" size="large" onAction = "fncOnAction" /> <button id = "bt2" label = "Avelino"
getImage="fncGetImage" size="large" onAction = "fncOnAction" /> </group> </tab> </tabs> </ribbon> </customUI>
This way the image is defined in the function fncGetiImage. See the function below:
Public Sub fncGetImage(control As IRibbonControl, ByRef Image) On Error GoTo fError Dim strPath As String Dim strImageName As String strPath = CurrentProject.Path & "\images\" Select Case control.Id Case "bt1"
strImageName = "feed.png" Case "bt2"
strImageName = "avel.gif" End Select If InStr(strImageName, ".png") > 0 Or InStr(strImageName, ".ico") > 0 Then Set Image = LoadImage(strPath & strImageName) Else Set Image = LoadPicture(strPath & strImageName) End If fError_Exit: Exit Sub fError: Select Case Err.Number Case 2220 MsgBox "Button Image " & control.Id & _
" not found on the path...", vbInformation, "Warn" Case Else MsgBox "Erro: " & Err.Number & vbCrLf & Err.Description, _
vbCritical, "Warn", Err.HelpFile, Err.HelpContext End Select Resume fError_Exit: End Sub
I made an example file that changes the image at runtime of a gallery control, so you can have a better idea of what can be done.
See the example:
Video Class:
In this vídeo class you will have an brief presentation about the use of external images, and will see the presentation of the example file that uses the gallery control, at runtime.
Links |
Subjects |
---|---|
Brief presentation of MontaRibbons
Structural concept of the XML used
How to disable all the upper ribbon of the Access
Using images from the Office’s gallery
Using internal controls of the Office
Customizing the quick toolbar
Customizing the Office Button
How to create a custom ribbon |
|
Setting the control splitButton
Setting the control menu
Differences between the controls splitButton and menu
Exporting the ribbons for your applications
How to give functionality to the buttons on the ribbon |
|
Changing the controls at runtime, using the attributes gets
How to configure the ribbon for the language exchange
How to hide / disable the buttons on the ribbon, depending on the User logged |
|
Images (GIF, JPEG, PNG e ICO) taken from the attachment type field |
|
FAQ | |
Combobox and Dropdown, in practice | |
All the details about how to purchase |