Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

Create dinamic controls and locate them with a For .. Next

$
0
0
Hi all,

I want need to create dinamic labels and textbox, accourding to the numbers of days of the month.

For example "January" have 31 days.

I have created Declare a label.

Code:

'Declare txtdias.labels
    Friend WithEvents txtdias As System.Windows.Forms.Label

into the form.load I have created arrays for years and months. In case the meses = 1 it means is January, so it should to be a calendar of 31 days.

Code:

Dim años() As String = {"2014", "2015", "2016", "2017", "2018", "2020", "2021", "2022", "2023", "2024"}
        Dim meses() As String = {"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"}
        CBmes.Items.AddRange(meses)
        CBAño.Items.AddRange(años)
        Initext()
        txtdate.Text = Date.Today.Year
        txtmonth.Text = Date.Today.Month
        If  txtmonth.Text = 1 Then
            CBmes.Text = meses(0)
End if

What I need to do is name the txtdias with a For Next from Day 1 to Day 31 for the month 1, which is January. But I recieved this error: "Object reference not set to an instance of an object."

Also I need to located several labels every 50 positions vertically into the form.

Code:


If txtmonth.Text = 1 Then
            For i As Integer = 1 To 31 Step +1
                Me.txtdias.Name = "txtdias" & i
                For j As Integer = 80 To 600 Step +50
                    Me.txtdias.Location = New Point(62, j)
                Next j
                Me.Controls.Add(Me.txtdias)
            Next i
        End If

May I need to create "Friend WithEvents txtdias As System.Windows.Forms.Label" 31 times?

Any one have idea how to do this?

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>