aran_ghasmi
New Member
Hello, I want to add a panel by each clicking on a button. How should I do this? Please help me ... Thank you
'globals ...
Private posLeft, posTop As Int
Private numPanels As Int = 1
Sub Button1_Click
Dim pnl As Panel
pnl.Initialize("MyPanels")
pnl.Tag = numPanels
pnl.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
Activity.AddView(pnl, posLeft, posTop, 100dip, 60dip)
posLeft = posLeft + 50dip
posTop = posTop + 50dip
numPanels = numPanels +1
End Sub
Sub MyPanels_Click
Dim p As Panel = Sender
Log($"You have clicked Panel # ${p.Tag}"$)
End Sub
You probably made an error when you changed the code. You need to include the new code in your post. Use the "Insert --> Code" option. (It is midnight for @mangojack so he might not answer for a while).... i change your code for this work
'posLeft removed from Globals
Sub Button1_Click
Activity.AddView(CreatePanel, 5dip, posTop, 48%x, 48%x) 'height same as width
numPanels = numPanels +1
Activity.AddView(CreatePanel, 51%x, posTop, 48%x, 48%x)
numPanels = numPanels +1
posTop = posTop + 48%x + 5dip
End Sub
Sub CreatePanel () As Panel
Dim pnl As Panel
pnl.Initialize("MyPanels")
pnl.Tag = numPanels
pnl.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
Return pnl
End Sub
Sub MyPanels_Click
Dim p As Panel = Sender
Log($"You have clicked Panel # ${p.Tag}"$)
End Sub