displaying .jpg from a button

magnuma1

Member
Licensed User
Longtime User
Hi all,

This is a simple question for most, but I'm still learning.

Now for the question. When clicking on a button, how do I get the button click to display a jpg image I have?

Thanks.
 

Cableguy

Expert
Licensed User
Longtime User
In the buttons click event change the buttons background
 
Upvote 0

magnuma1

Member
Licensed User
Longtime User
I'm getting closer. Here is the error I get:

Compiling code. Error
Error parsing program.
Error description: Undeclared variable 'button2' is used before it was assigned any value.
Occurred on line: 57
Button2.setbackgroundimage(LoadBitmap(File.dirassets,"credits.jpg"))

My code looks like this:

Sub Button2_Click
Button2.setbackgroundimage(LoadBitmap(File.dirassets,"credits.jpg"))
End Sub
 
Upvote 0

clx

Member
Licensed User
Longtime User
here you go..

B4X:
'Activity module
Sub Process_Globals
End Sub

Sub Globals
' declare your image variable which is credits.jpg
Dim creditButtonImage As Bitmap

' tell the compiler you are setting up a button
Dim creditButton As Button

End Sub

Sub Activity_Create(FirstTime As Boolean)

' load the image into memory
creditButtonImage.Initialize(File.DirAssets, "credits.jpg")
'
' load the apps main layout
Activity.LoadLayout("main1")

End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub creditButton_Click

' here set the creditButton you told the compiler about and call setbackgroundimage with the file you earlier loaded into memory
creditButton.setbackgroundimage(LoadBitmap(File.dirassets,"credits.jpg"))

End Sub
 
Last edited:
Upvote 0

magnuma1

Member
Licensed User
Longtime User
Well, we are getting closer to what I want. Now when I click on Button2, the JPG file overlays Button2. I would like it to replace the current view with just the JPG image.
 
Upvote 0

clx

Member
Licensed User
Longtime User
B4X:
Sub creditButton_Click
Activity.SetBackgroundImage(LoadBitmap(File.dirassets,"credits.jpg"))
End Sub
 
Last edited:
Upvote 0
Top