[EDITED] How to open PNG files to display in a BevelButton

Here is the sample code for anyone else looking to edit a picture based on a list of picture files presented in a PopupMenu the user selects from:

Var myPicture As FolderItem = App.ExecutableFile.Parent.Child("pics").Child(PopupMenu1.SelectedRow)
If myPicture <> Nil AND myPicture.Exists Then
  Try 
    Var pic1 As Picture
    pic1 = Picture.Open(myPicture)
    ContainerControl.BevelButton1.Icon = pic1
  Catch e As RuntimeException
    App.errorString = Str(e.ErrorNumber) + " - " + e.Message
    App.ErrorHandlerMethod
  End Try
End If

The PopupMenu has an Open Event Handler and the code is:

Var f As FolderItem = App.ExecutableFile.Parent.Child("pics")
If f.Exists Then
  Try 
    For Each fileListItem As FolderItem In f.Children
      PopupMenu1.AddRow(fileListItem.Name)
    Next
  Catch e As RuntimeException
    App.errorString = Str(e.ErrorNumber) + " - " + e.Message
    App.ErrorHandlerMethod
  End Try
End If

Hope this helps!

2 Likes

Added two cases in Feedback requesting the addition of this sample code:

BevelButton.Icon – <https://xojo.com/issue/63484>

PopupMenu.Addrow() – <https://xojo.com/issue/63483>

These two additions should make life a lot easier for new users.
I used the sample code in a prefs settings window, app is coming out soon.

1 Like