iOS Question Change color a button

Hector Alcala

Member
Licensed User
Hi, I would like to optimize my routine that I use to change the color of a particular button.
This is the routine I use (ChangeColor)

Sub Process_Globals
Private btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11, btn12 As Button
Private Colorx As String = Colors.RGB(91,208,18)
End Sub

Sub Application_Start (Nav As NavigationController)
:
:
ChangeColor(4)
End Sub

Sub ChangeColor(btnx As Int)
Select btnx
Case 1
btn1.Color = Colorx
Case 2
btn2.Color = Colorx
Case 3
btn3.Color = Colorx
Case 4
btn4.Color = Colorx
Case 5
btn5.Color = Colorx
Case 6
btn6.Color = Colorx
Case 7
btn7.Color = Colorx
Case 8
btn8.Color = Colorx
Case 9
btn9.Color = Colorx
Case 10
btn10.Color = Colorx
Case 11
btn11.Color = Colorx
Case 12
btn12.Color = Colorx
End Select
End Sub

Any suggestions ?
 

Hector Alcala

Member
Licensed User
Hi, Excuse me for not explaining myself well. I need to change the color of a button between 100. The example was not very clear.

ChangeColor(I) where I is a random number from 1 to 100. I currently use a routine using the select statement. In the example I only placed 12 cases to simplify.
 

Hector Alcala

Member
Licensed User
My problem is that the buttons must be in very specific places, for which I do not have a mathematical formula to be able to place them.
 

Hector Alcala

Member
Licensed User
The routine to place each button in its place would be very large and what I'm looking for is to simplify programming
 

Hector Alcala

Member
Licensed User
For the location of the buttons you suggest something like this:

Dim buttons(100) As Button
For I = 1 To 100
Select I
Case 1
buttons(I).Top = 1
buttons(I).Left = 1
Case 2
buttons(I).Top = 12
buttons(I).Left = 3
Case 3
buttons(I).Top = 5
buttons(I).Left = 20
:
:
:
End Select
Next
 

Sviluppatori Liceo Giovio

Member
Licensed User
so you're saying that there is no formula at all to the positions? Alright.
Well you can make this much shorter. Since you're defining each button via code, you'll need to initialize them and then add them to the panel.
So say you're adding it to the page's root panel. You'll need to do
For I = 1 to 100
buttons(I).Initialize("...",buttons(I).Style...)

Page1.Rootpanel.Addview(buttons(1),1,1,width,height)
Page1.Rootpanel.Addview(buttons(2),12,3,width,height)

I still don't understand why you need so many buttons.
 
Top