Differenze tra le versioni di "Creare un Form mediante la Classe Window"

Da Gambas-it.org - Wikipedia.
Riga 5: Riga 5:
  
 
Nel seguente esempio creeremo diversi ''Form'' mediante la Classe ''Window'':
 
Nel seguente esempio creeremo diversi ''Form'' mediante la Classe ''Window'':
  '''Private''' w As Window
+
  '''Private''' w As <FONT color=#B22222>Window</font>
 
  '''Private''' bt As Button
 
  '''Private''' bt As Button
 
   
 
   
Riga 16: Riga 16:
 
   
 
   
 
  <FONT color=#006400>' ''Creiamo un nuovo "Form":''</font>
 
  <FONT color=#006400>' ''Creiamo un nuovo "Form":''</font>
       With w = New Window As "w"
+
       With w = New <FONT color=#B22222>Window</font> As "w"
 
         .W = 300
 
         .W = 300
 
         .H = 200
 
         .H = 200
Riga 43: Riga 43:
 
  '''Public''' Sub creaTasto()
 
  '''Public''' Sub creaTasto()
 
    
 
    
   With bt = New Button(w) As "bt"
+
   With bt = New Button(<FONT color=#B22222>w</font>) As "bt"
 
     .X = 20
 
     .X = 20
 
     .Y = 20
 
     .Y = 20

Versione delle 08:49, 12 feb 2013

Poiché l'oggetto Form appartiene alla categoria dell'oggetto Window, è possibile creare un Form autonomo semplicemente dichiarando ed istanziando un oggetto Window per mezzo di una variabile di tipo Window, con la quale sarà anche gestito.

Detti Form creati mediante la Clase Window potranno contenere regolarmente degli oggetti.


Nel seguente esempio creeremo diversi Form mediante la Classe Window:

Private w As Window
Private bt As Button


Public Sub Button1_Click()

 Dim j As Byte

   For j = 0 To 4

' Creiamo un nuovo "Form":
     With w = New Window As "w"
       .W = 300
       .H = 200
       .Caption = "num. " & CStr(j)
       .Background = &111111 * (j + 1000)
       .Show
     End With

' Poniamo su ciascun nuovo "Form" un "Button":
     creaTasto()
   
   Next

End


Public Sub w_Open()
 
' Per ogni nuovo "From" creato, che si apre,
' ne vediamo in console il nome:
  Print w.Caption
 
End


Public Sub creaTasto()
 
  With bt = New Button(w) As "bt"
    .X = 20
    .Y = 20
    .W = 100
    .H = 40
    .Background = Color.Yellow
    .Text = "Tasto " & w.Caption
  End With
 
End


Public Sub bt_Click() ' I "Button" presenti sui nuovi "Form" sono regolarmente funzionanti
 
  Print "Premuto " & Last.Text
 
End