miércoles, 5 de septiembre de 2007

Progress Bar en ASP.NET 2.0

Buscando Barras de progreso en Internet me topé con uno de esos controles dll que funcionaba a la perfección, pero pedia un donativo (practicamente shareware con alerta y todo) para el control. Asi que decidí ver como funcionaba y publicar mi propio control para uso público. Aqui les dejo el código fuente (ProgressBar.ascx y ProgressBar.ascx.vb)

ProgressBar.ascx

<% Control Language="VB" AutoEventWireup="false" CodeFile="ProgressBar.ascx.vb" Inherits="componentes_ProgressBar" %>
<table cellspacing="1" cellpadding="0" border="0" style="border-color:Blue;border-width:1px;border-style:solid;height:20px;width:200px;"><tr><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#0000ff;"></td><td style="background-color:#d3d3d3;"></td><td style="background-color:#d3d3d3;"></td><td style="background-color:#d3d3d3;"></td><td style="background-color:#d3d3d3;"></td><td style="background-color:#d3d3d3;"></td><td style="background-color:#d3d3d3;"></td><td style="background-color:#d3d3d3;"></td></tr></table>



ProgressBar.ascx.vb

Partial Class componentes_ProgressBar : Inherits System.Web.UI.UserControl
Private _forecolor As Color = Color.Blue
Private _backgroundcolor As Color = Color.LightGray
Private _width As String = "200px"
Private _valor As Integer = 0
Private _maxCuadros As Integer = 30

Public Property ForeColor() As Color
Get
Return
_forecolor
End Get
Set
(ByVal value As Color)
Me._forecolor = value
End Set
End Property

Public Property
BackgroundColor() As Color
Get
Return
_backgroundcolor
End Get
Set
(ByVal value As Color)
Me._backgroundcolor = value
End Set
End Property

Public Property
MaxCuadros() As Integer
Get
Return
_maxCuadros
End Get
Set
(ByVal value As Integer)
_maxCuadros
= value
End Set
End Property

Public Property
Width() As String
Get
Return
_width
End Get
Set
(ByVal value As String)
_width
= value
End Set
End Property

Function
ToHexColor(ByVal c As Color) As String
Return
"#" + c.ToArgb().ToString("x").Substring(2)
End Function

Public Property
Value() As Integer
Get
Return
_valor
End Get
Set
(ByVal value As Integer)
If value > 100 Then value = 100
If value < 0 Then value = 0
_valor = value
End Set
End Property

Protected Overrides Sub
Render(ByVal Output As HtmlTextWriter)
Dim i As Integer
Dim
vreal As Integer = CInt((_valor * _maxCuadros / 100) + 0.5)
Dim fcolor As String = ToHexColor(_forecolor)
Dim bcolor As String = ToHexColor(_backgroundcolor)
Dim c As String
Output.Write("<table cellspacing=""1"" cellpadding=""0"" border=""0"" style=""border-color:Blue;border-width:1px;border-style:solid;height:20px;width:" & _width & ";""><tr>")
For i = 1 To _maxCuadros
c
= IIf(vreal < i, bcolor, fcolor)
Output.Write(
"<td style=""background-color:" & c & ";""></td>")
Next
Output.Write("</tr></table>")
End Sub
End Class



1 comentario:

Anónimo dijo...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Vinho, I hope you enjoy. The address is http://vinho-brasil.blogspot.com. A hug.