The Life of a View
I'm pretty much a beginner, so here's something I learned regarding views and container views. I guess the experts may consider this stuff obvious, but it wasn't to me!
I was initially confused by the error thrown up by the following code:
Code:
Dim pnlShow As Panel
pnlShow.Initialize("pnlShow")
pnlshow.Color=Colors.Yellow
pnlshow.SetLayout(2,3,200,30)
I got an error on the "SetLayout" line which I could not get my head round.
I did not realise that until you actually added this view to another view, you could not set positional information. I couldn't understand why I could set the color of the panel, but not it's position.
Thanks to the forums, I discovered that once you add the panel to an Activity or to an already "active" view, you can then set the positional data, as below:
Code:
Dim pnlShow As Panel
pnlShow.Initialize("pnlShow")
pnlshow.Color=Colors.Yellow
Activity.AddView(pnlshow,2,3,200,30) 'Bring to life by adding to Activity
And now of course, you can change its layout any time you like in code.
The same thing applies to other views, for example the button view. This code gives an error on the line "btnTest.Left=3"
Code:
Dim btnTest As Button
btnTest.Initialize("btnTest")
btnTest.Text="Press me"
btnTest.Left=3
This code gives the same error for the same reason - although the button view "exists" in memory, it has not been added to a container such as the Activity, or another "active" container view such as a panel, and so positional information is meaningless. The correct code is shown below:
Code:
Dim btnTest As Button
btnTest.Initialize("btnTest")
btnTest.Text="Press me"
Activity.AddView(btnTest,3,50,76,76) 'Bring to life by adding to Activity
Hope this is of use. Lots more to learn - great thread!
JMB