Italian Matrice di pulsanti...

Spectre

Active Member
Licensed User
Longtime User
Scusate l'ignoranza ma.... in VB.Net sono cose ovvie qui no....

ho creato una matrice di bottoni. dim MyMenuButton(8) as Button
li aggiungo ad un pannello esistente fatto con designer, a cui li aggiungo.
Quando tento di intercettare il click (sub click) mi restituisce questo errore: sender non inizializzato...


B4X:
activity create (first time as boolean)
  For i = 0 To 8 
        Dim But As Button
          But.Initialize("MyMenuButton")
        But.Text = ""
        But.Tag = i
          But.TextSize=15
        But.TextColor=Colors.Blue
        But.text= "BUT" & i
     
        MyMenuButton(i) = But
        If i=0 OR i=1 OR i=2 Then         
            panMenuButton.addView(MyMenuButton(i),i*80dip ,1dip,80dip, 80dip)
        End If
        If i=3 OR i=4 OR i=5 Then
            panMenuButton.addView(MyMenuButton(i),(i-3)*80dip ,85dip,80dip, 80dip)
        End If

        If i=6 OR i=7 OR i=8 Then
            panMenuButton.addView(MyMenuButton(i),(i-6)*80dip ,165dip,80dip, 80dip)
        End If
    Next 
    panMenuButton.Height=(MyMenuButton(0).Height*9)+1dip
    panMenuButton.Width=Activity.Width
    panMenuButton.Color=Colors.Transparent

 
    MyMenuButton(0).Text="MAP"
    MyMenuButton(1).Text="MAP OFF"
    MyMenuButton(2).Text="MAP FULL"
    MyMenuButton(3).Text="CROSS"
    MyMenuButton(4).Text="RELOD WP"
    MyMenuButton(5).Text="WP FIT" 
    MyMenuButton(6).Text="CANC NAVI"
    MyMenuButton(7).Text="CANC WP"
    MyMenuButton(8).Text="TRAK"
end sub

Sub MyMenuButton_Click
 
      Dim Send As Button      
     Send = Sender
 
    Select Case  Send.Tag
 
        Case 0" 
     
        Case 1           
         
        Case 2     
         
        Case 3
     
        Case 4
     
        Case 5
     
        Case 6     
     
        Case 7
     
        Case 8 
 
    End Select

End Sub
 
Last edited:

Spectre

Active Member
Licensed User
Longtime User
Non ho capito... Che sub é???
I pulsanti li creo all' inizio in activity create, poi devo intercettare l'evento del tasto premuto in runtime...
Il codice sopra non capisco come si ponga...
 

Spinter

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals

'These global variables will be declared once when the application starts.

'These variables can be accessed from all modules.

End Sub

Sub Globals

'These global variables will be redeclared each time the activity is created.

'These variables can only be accessed from this module.

End Sub


Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")

'creo bottoni!
For i = 0 To 8

        Dim But As Button
          But.Initialize("MyMenuButton")
        But.Text = ""
        But.Tag = i
          But.TextSize=15
        But.TextColor=Colors.Blue
        But.text= "BUT" & i


    Select Case  i
        Case 0
      But.Text="MAP"
        Case 1    
      But.Text= "MAP OFF"
        Case 2
      But.Text= "MAP FULL"
        Case 3
      But.Text="CROSS"
        Case 4
      But.Text="RELOD WP"
        Case 5
      But.Text="WP FIT"
        Case 6
      But.Text="CANC NAVI"
        Case 7
      But.Text="CANC WP"
        Case 8
      But.Text="TRAK"
    End Select

        'MyMenuButton(i) = But'
        If i=0 OR i=1 OR i=2 Then  
            Activity.addView(But,i*80dip ,1dip,80dip, 80dip)
          
        End If
        If i=3 OR i=4 OR i=5 Then
          Activity.addView(But,(i-3)*80dip ,85dip,80dip, 80dip)
        End If

        If i=6 OR i=7 OR i=8 Then
            Activity.addView(But,(i-6)*80dip ,165dip,80dip, 80dip)
        End If
    Next
    Activity.Height=(But.Height*9)+1dip
    Activity.Width=Activity.Width
    Activity.Color=Colors.Transparent

End Sub

'il tuo menù

Sub MyMenuButton_Click
Dim Send As Button
    Send = Sender
    Log(Send.Tag)
Msgbox("",Send.Tag)
End Sub



puoi anche fare cosi nel tuo bottone!!

B4X:
Sub MyMenuButton_Click

Dim Send AsButton
Send = Sender
SelectCase Send.Tag
Case0
Log(0)
Case1
Log(1)
Case2
Log(2)
Case3
Log(3)
Case4
Log(4)
Case5
Log(5)
Case6
Log(6)
Case7
Log(7)
Case8
Log(8)
EndSelect
End Sub
 
Last edited:

Spectre

Active Member
Licensed User
Longtime User
ok adesso è più chiaro... ma nel mio codice cosa è che provocava il problema? il fatto che li aggiungevo al panel?
 

LucaMs

Expert
Licensed User
Longtime User
Scusate l'ignoranza ma.... in VB.Net sono cose ovvie qui no....

ho creato una matrice di bottoni. dim MyMenuButton(8) as Button
li aggiungo ad un pannello esistente fatto con designer, a cui li aggiungo.
Quando tento di intercettare il click (sub click) mi restituisce questo errore: sender non inizializzato...


B4X:
activity create (first time as boolean)
  For i = 0 To 8
        Dim But As Button
          But.Initialize("MyMenuButton")
        But.Text = ""
        But.Tag = i
          But.TextSize=15
        But.TextColor=Colors.Blue
        But.text= "BUT" & i

        MyMenuButton(i) = But
        If i=0 OR i=1 OR i=2 Then    
            panMenuButton.addView(MyMenuButton(i),i*80dip ,1dip,80dip, 80dip)
        End If
        If i=3 OR i=4 OR i=5 Then
            panMenuButton.addView(MyMenuButton(i),(i-3)*80dip ,85dip,80dip, 80dip)
        End If

        If i=6 OR i=7 OR i=8 Then
            panMenuButton.addView(MyMenuButton(i),(i-6)*80dip ,165dip,80dip, 80dip)
        End If
    Next
    panMenuButton.Height=(MyMenuButton(0).Height*9)+1dip
    panMenuButton.Width=Activity.Width
    panMenuButton.Color=Colors.Transparent


    MyMenuButton(0).Text="MAP"
    MyMenuButton(1).Text="MAP OFF"
    MyMenuButton(2).Text="MAP FULL"
    MyMenuButton(3).Text="CROSS"
    MyMenuButton(4).Text="RELOD WP"
    MyMenuButton(5).Text="WP FIT"
    MyMenuButton(6).Text="CANC NAVI"
    MyMenuButton(7).Text="CANC WP"
    MyMenuButton(8).Text="TRAK"
end sub

Sub MyMenuButton_Click

      Dim Send As Button 
     Send = Sender

    Select Case  Send.Tag

        Case 0"

        Case 1      
    
        Case 2
    
        Case 3

        Case 4

        Case 5

        Case 6

        Case 7

        Case 8

    End Select

End Sub


Il tuo programma funziona, ha solo un difettuccio: l'array va dichiarato con un elemento in più: MyMenuButton(9)
 

Attachments

  • lm_ProvaButtons.zip
    7.9 KB · Views: 347
Top