UserControl: Calendario - Mes

UserControl para mostrar el mes seleccionado. Con opción de rellenado de notas.

Vista del user control:

Parámetros de entrada:

  • MesSeleccionado: Tipo Integer
  • AñoSeleccionado: Tipo Integer

Código:

Public Class MesControl
 
#Region "Declaración de variables"
    ' Variables locales
    Private MesSelec As Integer
    Private AñoSelec As Integer
 
    ' Variables públicas
    Public Property MesSeleccionado As Integer
        Get
            Return MesSelec
        End Get
        Set(ByVal value As Integer)
            MesSelec = value
        End Set
    End Property
    Public Property AñoSeleccionado As Integer
        Get
            Return AñoSelec
        End Get
        Set(ByVal value As Integer)
            AñoSelec = value
        End Set
    End Property
#End Region
 
#Region "Acciones del control"
    Private Sub MesControl_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Rellenar()
        Colocacion()
    End Sub
#End Region
 
#Region "Procedimientos"
    Private Sub Rellenar()
        For Each NombreLis In Me.TableLayoutPanel1.Controls
            If TypeOf NombreLis Is ListView Then
                With NombreLis
                    .Items.Clear()
                    .View = View.Details
                    .GridLines = True
                    .FullRowSelect = True
                    .HeaderStyle = ColumnHeaderStyle.None
                    .Columns.Add("", 250)
                    .Scrollable = False
                End With
            End If
        Next
    End Sub
 
    Private Function PosicionPrimerDia() As Integer
        Dim MyDate As Date
        Dim Posicion As Integer
        MyDate = DateSerial(AñoSelec, MesSelec, 1)
        Posicion = Weekday(MyDate, FirstDayOfWeek.Monday)
        Return Posicion
    End Function
 
    Private Sub Colocacion()
        Dim NumeroDias() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
        Dim AñoBisiesto As Integer
        Dim ListadoExcluir() As String = {"DiaSemana1", "DiaSemana2", "DiaSemana3", "DiaSemana4", "DiaSemana5", "DiaSemana6", "DiaSemana7"}
        Dim DiasDelMes As New List(Of Label)
        Dim Conta, Conta2 As Integer
        Dim Salto As Boolean = False
        AñoBisiesto = AñoSelec Mod 4
        If AñoBisiesto = 0 Then
            NumeroDias(2) = 29
        End If
        For Each NombreLabel In Me.TableLayoutPanel1.Controls
            If TypeOf NombreLabel Is Label And Not Array.IndexOf(ListadoExcluir, NombreLabel.Name) > -1 Then
                DiasDelMes.Add(NombreLabel)
            End If
        Next
        DiasDelMes.Reverse()
        For Each Dia In DiasDelMes
            Dim DiaCompa, NombreLis, NumeroDia() As String
            Dim AsociacionLista As ListView
            NumeroDia = Split(Dia.Name, "txtDiaMes")
            NombreLis = "lisDiaMes" & NumeroDia(1)
            AsociacionLista = Me.TableLayoutPanel1.Controls.Item(Me.TableLayoutPanel1.Controls.IndexOfKey(NombreLis))
            Conta += 1
            Conta2 += 1
            Dia.Hide()
            Dia.Text = Nothing
            AsociacionLista.Hide()
            If Conta = PosicionPrimerDia() And Salto = False Then
                Conta = 1
                Salto = True
                AsociacionLista.Show()
                Dia.Show()
                Dia.Text = Conta
            ElseIf Conta2 > PosicionPrimerDia() And Conta <= NumeroDias(MesSelec) Then
                AsociacionLista.Show()
                Dia.Show()
                Dia.Text = Conta
            End If
            DiaCompa = Conta & "/" & MesSelec & "/" & AñoSelec
            If Date.Today.ToString("dd/M/yyyy") = DiaCompa Then
                With Dia
                    .BackColor = Color.FromArgb(19, 76, 149)
                    .ForeColor = Color.White
                    .Margin = New Padding(0)
                End With
            Else
                With Dia
                    .BackColor = Color.FromArgb(224, 224, 224)
                    .ForeColor = Color.Black
                    .Margin = New Padding(3)
                End With
            End If
        Next
    End Sub
#End Region
 
End Class

Vista en funcionamiento:

Descarga del control: eventoscalendario.rar


Navegación

<html><a href=“/softwareprogramacion”>Software de programación</a></html>

Ayuda al servidor