Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Aqua Bar - AquaBar.vb

AquaBar.vb

Caricato da: Totem
Scarica il programma completo

  1. Public Class AquaBar
  2.     Public Enum AquaBarColors
  3.         LightBlue
  4.         Red
  5.         Green
  6.         Purple
  7.     End Enum
  8.  
  9.     Private p_Value, p_Minimum, p_Maximum As Int64
  10.     Private p_BarColor As AquaBarColors
  11.  
  12.     ''' <summary>
  13.     ''' Imposta il valore visualizzato dalla barra.
  14.     ''' </summary>
  15.     ''' <value>Un intero compreso tra Minimum e Maximum.</value>
  16.     ''' <returns></returns>
  17.     ''' <remarks></remarks>
  18.     Public Property Value() As Int64
  19.         Get
  20.             Return p_Value
  21.         End Get
  22.         Set(ByVal Value As Int64)
  23.             If Value >= p_Minimum And Value <= p_Maximum Then
  24.                 Dim Percent As Double
  25.                 Dim BarWidth As Int16
  26.                 p_Value = Value
  27.                 Percent = (p_Value - p_Minimum) / (p_Maximum - p_Minimum)
  28.                 BarWidth = Me.Width * Percent
  29.                 pnlBar.Width = BarWidth
  30.             Else
  31.                 Throw New ArgumentOutOfRangeException
  32.             End If
  33.         End Set
  34.     End Property
  35.  
  36.     ''' <summary>
  37.     ''' Imposta il minimo valore possibile visualizzato dal controllo.
  38.     ''' </summary>
  39.     ''' <value>Un intero a 64 bit, maggiore di zero.</value>
  40.     ''' <returns></returns>
  41.     ''' <remarks></remarks>
  42.     Public Property Minimum() As Int64
  43.         Get
  44.             Return p_Minimum
  45.         End Get
  46.         Set(ByVal Value As Int64)
  47.             If Value >= 0 Then
  48.                 p_Minimum = Value
  49.                 'Controlla che Maximum non sia minore di Minimum
  50.                 If p_Minimum > p_Maximum Then
  51.                     p_Maximum = p_Minimum + 1
  52.                 End If
  53.             Else
  54.                 Throw New ArgumentOutOfRangeException
  55.             End If
  56.         End Set
  57.     End Property
  58.  
  59.  
  60.     ''' <summary>
  61.     ''' Imposta il massimo valore possibile visualizzato dal controllo.
  62.     ''' </summary>
  63.     ''' <value>Un intero a 64 bit, maggiore di zero.</value>
  64.     ''' <returns></returns>
  65.     ''' <remarks></remarks>
  66.     Public Property Maximum() As Int64
  67.         Get
  68.             Return p_Maximum
  69.         End Get
  70.         Set(ByVal Value As Int64)
  71.             If Value >= 0 Then
  72.                 p_Maximum = Value
  73.                 'Controlla che Minimum non sia maggiore di Maximum
  74.                 If p_Maximum < p_Minimum Then
  75.                     p_Minimum = p_Maximum - 1
  76.                 End If
  77.             Else
  78.                 Throw New ArgumentOutOfRangeException
  79.             End If
  80.         End Set
  81.     End Property
  82.  
  83.     ''' <summary>
  84.     ''' Imposta il colore della barra.
  85.     ''' </summary>
  86.     ''' <value>Un colore tra: azzurro, verde, viola e rosso.</value>
  87.     ''' <returns></returns>
  88.     ''' <remarks></remarks>
  89.     Public Property BarColor() As AquaBarColors
  90.         Get
  91.             Return p_BarColor
  92.         End Get
  93.         Set(ByVal Value As AquaBarColors)
  94.             p_BarColor = Value
  95.             Select Case Value
  96.                 Case AquaBarColors.LightBlue
  97.                     imgCenter.Image = imgColors.Images("button_center.PNG")
  98.                     imgStart.Image = imgColors.Images("button_start_trunc.PNG")
  99.                     imgEnd.Image = imgColors.Images("button_end_trunc.PNG")
  100.  
  101.                 Case AquaBarColors.Green
  102.                     imgCenter.Image = imgColors.Images("button_center_green.PNG")
  103.                     imgStart.Image = imgColors.Images("button_start_trunc_green.PNG")
  104.                     imgEnd.Image = imgColors.Images("button_end_trunc_green.PNG")
  105.  
  106.                 Case AquaBarColors.Purple
  107.                     imgCenter.Image = imgColors.Images("button_center_purple.PNG")
  108.                     imgStart.Image = imgColors.Images("button_start_trunc_purple.PNG")
  109.                     imgEnd.Image = imgColors.Images("button_end_trunc_purple.PNG")
  110.  
  111.                 Case AquaBarColors.Red
  112.                     imgCenter.Image = imgColors.Images("button_center_red.PNG")
  113.                     imgStart.Image = imgColors.Images("button_start_trunc_red.PNG")
  114.                     imgEnd.Image = imgColors.Images("button_end_trunc_red.PNG")
  115.             End Select
  116.         End Set
  117.     End Property
  118.  
  119.     Public Sub New()
  120.         ' This call is required by the Windows Form Designer.
  121.         InitializeComponent()
  122.         p_Minimum = 0
  123.         p_Maximum = 100
  124.         p_Value = 100
  125.     End Sub
  126.  
  127.     Private Sub pnlBar_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pnlBar.Resize
  128.         'Controlla di non lasciare spazi vuoti
  129.         If imgCenter.Location.X + imgCenter.Width < imgEnd.Location.X Then
  130.             imgCenter.Width += imgEnd.Location.X - (imgCenter.Location.X + imgCenter.Width)
  131.         End If
  132.     End Sub
  133. End Class