Differenze tra le versioni di "Simulare una ProgressBar mediante una DrawingArea"
Da Gambas-it.org - Wikipedia.
(Creata pagina con "La simulazione di una "ProgressBar" mediante l'uso di una "DrawingArea", può essere utile, ad esempio, per utilizzare un colore diverso da quello standard fornito dal tema gr...") |
|||
(Una versione intermedia di uno stesso utente non è mostrata) | |||
Riga 9: | Riga 9: | ||
− | + | Public Sub Form_Open() | |
With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | ||
Riga 26: | Riga 26: | ||
End With | End With | ||
− | + | End | |
− | + | ||
+ | Public Sub Tempus_Timer() | ||
If (valore * 100) / DrawingArea1.W >= 100.0 Then tempus.Stop | If (valore * 100) / DrawingArea1.W >= 100.0 Then tempus.Stop | ||
Riga 34: | Riga 35: | ||
DrawingArea1.Refresh | DrawingArea1.Refresh | ||
− | + | End | |
+ | |||
− | + | Public Sub DrawingArea1_Draw() | |
With Paint | With Paint | ||
Riga 49: | Riga 51: | ||
End With | End With | ||
− | + | End | |
Nel codice seguente invece si darà un effetto arcobaleno: | Nel codice seguente invece si darà un effetto arcobaleno: | ||
− | + | Private DrawingArea1 As DrawingArea | |
Private dw As Short | Private dw As Short | ||
Private dh As Short | Private dh As Short | ||
Riga 59: | Riga 61: | ||
− | + | Public Sub Form_Open() | |
With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" | ||
Riga 76: | Riga 78: | ||
End With | End With | ||
− | + | End | |
+ | |||
− | + | Public Sub Tempus_Timer() | |
If (valore * 100) / DrawingArea1.W >= 100.0 Then tempus.Stop | If (valore * 100) / DrawingArea1.W >= 100.0 Then tempus.Stop | ||
Riga 84: | Riga 87: | ||
DrawingArea1.Refresh | DrawingArea1.Refresh | ||
− | + | End | |
+ | |||
− | + | Public Sub DrawingArea1_Draw() | |
Dim c As Integer[] = [Color.Blue, Color.Green, Color.Yellow, Color.Red] | Dim c As Integer[] = [Color.Blue, Color.Green, Color.Yellow, Color.Red] | ||
Riga 102: | Riga 106: | ||
End With | End With | ||
− | + | End |
Versione attuale delle 12:12, 22 giu 2024
La simulazione di una "ProgressBar" mediante l'uso di una "DrawingArea", può essere utile, ad esempio, per utilizzare un colore diverso da quello standard fornito dal tema grafico.
Mostriamo di seguito una "DrawingArea" che simula il comportamento di un Oggetto "ProgressBar", ma di colore giallo:
Private DrawingArea1 As DrawingArea Private dw As Short Private dh As Short Private valore As Single Private tempus As Timer Public Sub Form_Open() With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" .X = 10 .Y = 10 .W = 300 .H = 50 .Background = Color.Red dw = .W / 2 dh = .H / 2 End With With tempus = New Timer As "Tempus" .Delay = 40 .Start End With End Public Sub Tempus_Timer() If (valore * 100) / DrawingArea1.W >= 100.0 Then tempus.Stop valore += 1.0 DrawingArea1.Refresh End Public Sub DrawingArea1_Draw() With Paint ' Imposta il colore giallo per la "ProgressBar" simulata: .Brush = .Color(Color.Yellow) .Rectangle(0, 0, valore, DrawingArea1.H) .Fill .Brush = .Color(Color.Blue) .DrawText(CStr(Fix((valore * 100) / DrawingArea1.W)) & "%", dw - (.TextExtents(CStr(valore)).W / 2), dh - (.TextExtents(CStr(valore)).H / 2), .TextExtents(CStr(valore)).W, .TextExtents(CStr(valore)).H, Align.Normal) .End End With End
Nel codice seguente invece si darà un effetto arcobaleno:
Private DrawingArea1 As DrawingArea Private dw As Short Private dh As Short Private valore As Single Private tempus As Timer Public Sub Form_Open() With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1" .X = 10 .Y = 10 .W = 300 .H = 50 .Background = Color.LightGray dw = .W / 2 dh = .H / 2 End With With tempus = New Timer As "Tempus" .Delay = 40 .Start End With End Public Sub Tempus_Timer() If (valore * 100) / DrawingArea1.W >= 100.0 Then tempus.Stop valore += 1.0 DrawingArea1.Refresh End Public Sub DrawingArea1_Draw() Dim c As Integer[] = [Color.Blue, Color.Green, Color.Yellow, Color.Red] Dim f As Float[] = [0, 0.34, 0.67, 1] With Paint ' Imposta un motivo arcobaleno orizzontale per la "ProgressBar" simulata: .Brush = .LinearGradient(valore, 0, valore, DrawingArea1.H, c, f) .Rectangle(0, 0, valore, DrawingArea1.H) .Fill .Brush = .Color(Color.Black) .DrawText(CStr(Fix((valore * 100) / DrawingArea1.W)) & "%", dw - (.TextExtents(CStr(valore)).W / 2), dh - (.TextExtents(CStr(valore)).H / 2), .TextExtents(CStr(valore)).W, .TextExtents(CStr(valore)).H, Align.Normal) .End End With End