Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 30
  1. #1

    [VB] Creare una Progressbar stile Windows 98

    Come faccio a creare una Progressbar tipo quella di Windows 98 che quando la barra di avanzamento blu raggiunge il testo al centro della Progressbar di colore nero diventa bianco? Capite cosa intendo? Tipo come succede in uTorrent?
    Grazie, ciao.

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    970
    Basta che ti crei un Custom Control, ti posto la base del codice.

    codice:
    Imports System.Drawing.Drawing2D
    
    Public Class SmoothProgressBar
        Private min As Integer = 0               ' Minimum value for progress range
        Private max As Integer = 100             ' Maximum value for progress range
        Private val As Integer = 75              ' Current progress
        Private barColor As Color = Color.Blue   ' Color of progress meter
        Private gradientinit As Color = Color.Black
        Private gradientfinal As Color = Color.Blue
        Private gradient As Boolean
        Private gradientType As System.Drawing.Drawing2D.LinearGradientMode
        Private GradientTextView As Boolean
    
        Protected Overrides Sub OnResize(ByVal e As EventArgs)
            ' Invalidate the control to get a repaint.
            Me.Invalidate()
        End Sub
    
        Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
            Dim g As Graphics = e.Graphics
            Dim brush As SolidBrush = New SolidBrush(barColor)
            Dim percent As Decimal = (val - min) / (max - min)
            Dim rect As Rectangle = Me.ClientRectangle
    
            ' Calculate area for drawing the progress.
            rect.Width = rect.Width * percent
            Label1.Location = New Point((Me.Width - Label1.Width) / 2, (Me.Height - Label1.Height) / 2)
            Label1.Text = CStr(CInt((percent * 100))) & "%"
    
            ' Draw the progress meter.
            If gradient = True Then
                Dim br As New LinearGradientBrush(Me.ClientRectangle, gradientinit, gradientfinal, gradientType)
                g.FillRectangle(br, rect)
            Else
                g.FillRectangle(brush, rect)
            End If
    
            ' Draw a three-dimensional border around the control.
            Draw3DBorder(g)
    
            ' Clean up.
            brush.Dispose()
            g.Dispose()
        End Sub
    
        Public Property GradientFillType() As System.Drawing.Drawing2D.LinearGradientMode
            Get
                Return GradientType
            End Get
            Set(ByVal value As System.Drawing.Drawing2D.LinearGradientMode)
                gradientType = value
                Me.Refresh()
            End Set
        End Property
    
        Public Property GradientColorInit() As Color
            Get
                Return gradientinit
            End Get
            Set(ByVal value As Color)
                gradientinit = value
                Me.Refresh()
            End Set
        End Property
    
        Public Property GradientColorFinal() As Color
            Get
                Return gradientfinal
            End Get
            Set(ByVal value As Color)
                gradientfinal = value
                Me.Refresh()
            End Set
        End Property
    
        Public Property GradientColor() As Boolean
            Get
                Return gradient
            End Get
            Set(ByVal value As Boolean)
                gradient = value
                Me.Refresh()
            End Set
        End Property
    
        Public Property GradientText() As Boolean
            Get
                Return Label1.Visible
            End Get
            Set(ByVal value As Boolean)
                Label1.Visible = value
                Label1.Refresh()
            End Set
        End Property
    
        Public Property GradientTextColor() As Color
            Get
                Return Label1.ForeColor
            End Get
            Set(ByVal value As Color)
                Label1.ForeColor = value
                Label1.Refresh()
            End Set
        End Property
    
        Public Property GradientTextFont() As Font
            Get
                Return Label1.Font
            End Get
            Set(ByVal value As Font)
                Dim p As New Font(value.Name, value.Size, value.Style)
                Label1.Font = p
                Label1.Refresh()
            End Set
        End Property
    
    
        Public Property Minimum() As Integer
            Get
                Return min
            End Get
    
            Set(ByVal Value As Integer)
                ' Prevent a negative value.
                If (Value < 0) Then
                    min = 0
                End If
    
                ' Make sure that the minimum value is never set higher than the maximum value.
                If (Value > max) Then
                    min = Value
                    min = Value
                End If
    
                ' Make sure that the value is still in range.
                If (val < min) Then
                    val = min
                End If
    
                ' Invalidate the control to get a repaint.
                Me.Invalidate()
            End Set
        End Property
    
        Public Property Maximum() As Integer
            Get
                Return max
            End Get
    
            Set(ByVal Value As Integer)
                ' Make sure that the maximum value is never set lower than the minimum value.
                If (Value < min) Then
                    min = Value
                End If
    
                max = Value
    
                ' Make sure that the value is still in range.
                If (val > max) Then
                    val = max
                End If
    
                ' Invalidate the control to get a repaint.
                Me.Invalidate()
            End Set
        End Property
    
        Public Property Value() As Integer
            Get
                Return val
            End Get
    
            Set(ByVal Value As Integer)
                Dim oldValue As Integer = val
    
                ' Make sure that the value does not stray outside the valid range.
                If (Value < min) Then
                    val = min
                ElseIf (Value > max) Then
                    val = max
                Else
                    val = Value
                End If
    
                ' Invalidate only the changed area.
                Dim percent As Decimal
    
                Dim newValueRect As Rectangle = Me.ClientRectangle
                Dim oldValueRect As Rectangle = Me.ClientRectangle
    
                ' Use a new value to calculate the rectangle for progress.
                percent = (val - min) / (max - min)
                newValueRect.Width = newValueRect.Width * percent
    
                ' Use an old value to calculate the rectangle for progress.
                percent = (oldValue - min) / (max - min)
                oldValueRect.Width = oldValueRect.Width * percent
    
                Dim updateRect As Rectangle = New Rectangle()
    
                ' Find only the part of the screen that must be updated.
                If (newValueRect.Width > oldValueRect.Width) Then
                    updateRect.X = oldValueRect.Size.Width
                    updateRect.Width = newValueRect.Width - oldValueRect.Width
                Else
                    updateRect.X = newValueRect.Size.Width
                    updateRect.Width = oldValueRect.Width - newValueRect.Width
                End If
    
                updateRect.Height = Me.Height
                ' Invalidate only the intersection region.
                Me.Invalidate(updateRect)
            End Set
        End Property
    
        Public Property ProgressBarColor() As Color
            Get
                Return barColor
            End Get
    
            Set(ByVal Value As Color)
                barColor = Value
                ' Invalidate the control to get a repaint.
                Me.Invalidate()
            End Set
        End Property
    
        Private Sub Draw3DBorder(ByVal g As Graphics)
            Dim PenWidth As Integer = Pens.White.Width
    
            g.DrawLine(Pens.DarkGray, _
                New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Top), _
                New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Top))
            g.DrawLine(Pens.DarkGray, _
                New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Top), _
                New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Height - PenWidth))
            g.DrawLine(Pens.White, _
                New Point(Me.ClientRectangle.Left, Me.ClientRectangle.Height - PenWidth), _
                New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Height - PenWidth))
            g.DrawLine(Pens.White, _
                New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Top), _
                New Point(Me.ClientRectangle.Width - PenWidth, Me.ClientRectangle.Height - PenWidth))
        End Sub
    
    End Class
    Sbagliare è umano, perseverare è diabolico.

  3. #3
    Non capisco ti spieghi meglio? Tutto questo codice? Ma hai capito bene cosa intendo?
    Grazie per la buona volonta, apetto risposta, ciao.

  4. #4
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    970
    Non esiste quel controllo, ovvero esiste la Progressbar ma non prevede mi sembra il testo all'interno. Quindi devi crearne una tu personalizzata come ho fatto con quella Class Library dove al centro della progress bar c'è la classica scritta 50%. Nella progressbar che ho fatto il testo non cambia colore e la barra è ha gradienti invece che a colore unico, ma con poche modifiche.
    Il codice è ridotto all'osso!!!!!
    Sbagliare è umano, perseverare è diabolico.

  5. #5
    Ok, ma il label1 si vede con lo sfondo grigio... non credo che sarà impossibbile visto che molti programmi di installazione hanno questa progressbar, credo che utilizzando la classe graphics sarà possibbile ma non so come fare!
    Cosa ne pensi? Grazie, ciao.

  6. #6
    Utente di HTML.it
    Registrato dal
    Apr 2009
    Messaggi
    970
    Azz ma sembra che parlo per niente....

    La ProgressBar che ti ho menzionato ha il testo centrale con lo sfondo trasparente, così:



    O così:



    Va bene??

    Sbagliare è umano, perseverare è diabolico.

  7. #7
    Ok, grazie... mi va bene comunque! Se ho problemi ti farò sapere... Scusa, ciao.

  8. #8
    Mi dici dove hai trovato il codice? Ciao.

  9. #9
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    758
    A dire la verità un controllo che fa quasi quello che chiedi esiste. Si chiama SSpanel e fa parte del pacchetto di oggetti compresi in Sheridan 3D Controls. L'OCX, che si chiama Threed32.ocx, è reperibile nel terzo CD di Visual Studio. Devi però aver cura di cambiare il colore della percentuale quando questa supera 50, il che vuol dire che, quando è esattamente 50, non puoi avere il "50" mezzo chiaro e mezzo scuro.

  10. #10
    Ah, ecco dove lo hai trovato... http://support.microsoft.com/kb/323088 ! Anche se lo hai un po modificato... Ciao.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.