Home Ask Login Register

Developers Planet

Your answer is one click away!

Mohamed Mando 2 weeks ago

vb.net - am making loop that creating a labels that can open a new form

hey everyone can someone help me with some codes in vb.net

i created a loop that can generate labels with my OleDbDataReader now i was wondering if i can make those labels open new form here is my code :

        Dim cnn As New OleDbCommand(query, con)
    Dim cmd As New OleDbDataAdapter(cnn)
    Dim dt As New DataTable()
    cmd.Fill(dt)
    Dim reader As OleDbDataReader
    reader = cnn.ExecuteReader()

    Dim number As Integer = 0
    Dim location As Integer = 0
    While reader.Read()

        Dim sensibleFont As New Font("Segoe UI", 15)

        Dim lb As New Label()
        lb.Name = "labb" + number.ToString
        lb.Size = New System.Drawing.Size(350, 40)
        lb.Location = New System.Drawing.Point(50, 15 + location)
        lb.Text = dt.Rows(number)(0).ToString()
        lb.ForeColor = Color.Black
        lb.Font = sensibleFont
        GroupBox1.Controls.Add(lb)

        Dim lb2 As New Label()
        lb2.Name = "labs" + number.ToString
        lb2.Size = New System.Drawing.Size(280, 40)
        lb2.Location = New System.Drawing.Point(10, 5 + location)
        lb2.Text = dt.Rows(number)(2).ToString()
        lb2.ForeColor = Color.Black
        lb2.Font = sensibleFont
        GroupBox2.Controls.Add(lb2)

        location += 40
        number += 1
    End While

    con.Close()

Answers


Pro Grammer 2 weeks ago

Create a sub that does what you want.

Private Sub OpenForm()
    Dim myForm As New MyForm()
    myForm.Show()
End Sub

During label creation, add a click event that uses this sub as it's handler

AddHandler lb.Click, AddressOf OpenForm

Post Status

Asked in 2 weeks ago
Viewed 1,952 times
Voted 10
Answered 1 times

Search




Leave an answer


Quote of the day: live life