Click here to Skip to main content
15,909,373 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I know how to generate label while running the program. now my question is how to put the generated labels in flow lay out panel so it will not affect other tools. JUST only in one collumn
and when i created a new label, the last label created must be move down and the new created label will go on top of it. pls do help me.


this is my code so far

VB
Public Class Form1
    Dim counter As Integer = 1
    Dim FontName As String = "Tw Cen MT"
    Dim FontSize As Integer = 8
    Dim FS As New Font(FontName, FontSize, FontStyle.Regular)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim lblTask As New Label
        lblTask.Name = "Label" & counter
        lblTask.Location = New Point(804, counter * 40)
        lblTask.Text = "You Just been Saved a name of" & TextBox1.Text
        lblTask.ForeColor = Color.White
        lblTask.BackColor = Color.FromArgb(95, 117, 146)
        lblTask.Width = 136
        lblTask.Height = 38
        lblTask.Font = FS
        Me.Controls.Add(lblTask)
        counter += 1
        lblTask.BringToFront()
    End Sub
End Class
Posted
Comments
CHill60 7-Jun-13 5:59am    
lblTask.BringToFront() is the correct way to get the newly created label to the top of the list.
What is happening when you run your code?
Crixalis Paul 14-Jun-13 22:11pm    
not to the front of the last label on the top of it
Sergey Alexandrovich Kryukov 7-Jun-13 11:30am    
Yes, you need to explain what's wrong with your code.
—SA

1 solution

You need to add the label to the flowLayoutPanel's control collection not the form's - Me.Controls.Add adds it to the form. Where flp.Controls.Add() adds it to a flowlayoutPanel named flp, as an example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900