Make buttons invisible

anaylor01

Well-Known Member
Licensed User
Longtime User
I create 16 buttons programmatically and I want for all the buttons to be invisible when any of the buttons are clicked. The code I use to create the buttons are below.

Code: Copy
Dim x, y As Int
Dim width, offsetX, offsetY As Int
    width = 37dip
    offsetX = 20'(100%x - width * sw - 10dip * 2  ) / 2
    offsetY = 20'(100%y - width * sw - 10dip * 2) / 2
    Dim Buttons(8, 2) As Button
    For x = 0 To sw
        For y = 0 To 1
            Dim b As Button
            b.Initialize("button") 'All buttons share the same event sub
            Activity.AddView(b,offsetX + x * (width + 3dip), offsetY + y * (width + 3dip), width, width)
            Buttons(x, y) = b 'store a reference to this view
        Next
    Next
 
Hey Erel, I used your code but it is only making one button invisible. The 9th button. So it is 2 rows with 8 buttons each row so it is the first button on the second row. SW is equal to 7 which counting zero that is 8. Any ideas?
 
Upvote 0
LOL. Thanks. That was the problem. I just wish I was smart enough to figure it out. LOL. I knew the 0,1 didn't look right. But that was as far as I got. LOL
 
Upvote 0
Hi Erel!

Sorry for my dull question, I don´t understand that. How can I make the button "btnSave" unvisible??
Buttons(btnSave).Visible = False? Doesn´t work (I defined "Buttons" as Button).
"btnSave.Visible = False" doesn´t work neither.
 
Upvote 0
What exactly do you want to do ?
If you have only one button then you should
Dim btnSave As Button in Globals
And then btnSave.Visible = False works.

Best regards.

Hello Klaus!
Yes, I did it exactly this way and the code stops at that line (btnSave.Visible = False)!??
I have only one button. Do I need a special library?
best regards
 
Last edited:
Upvote 0
You need to show more code to help you.
Without knowing what you have done it's difficult to help
Is the button defined in a layout file, or is it defined in the code etc ?

Best regards..

The button "btnSave" is defined in the layout. The relevant code is only:
Code: Copy
Sub Globals
    Dim btnSave As Button
    ....
End Sub

Sub Activity_Create(FirstTime As Boolean)
     btnSave.Visible = False
     .....

The debugger runs without problems. But when I run the app on the phone I get the error: "Program paused on line 43..."
I don´t know what else could be relevant.
 
Upvote 0
How about, put all buttons on a panel.
Panel.visible = False
 
Upvote 0
The button "btnSave" is defined in the layout. The relevant code is only:
Code: Copy
Sub Globals
    Dim btnSave As Button
    ....
End Sub

Sub Activity_Create(FirstTime As Boolean)
     btnSave.Visible = False
     .....

The debugger runs without problems. But when I run the app on the phone I get the error: "Program paused on line 43..."
I don´t know what else could be relevant.

It seems you set the buttons visibility before you load the layout. In this case btnSave ist not initialized.
 
Upvote 0
Back
Top