About Me

My photo
I'm an undergraduate of Sri Lanka Institute of Information Technology(SLIIT).

Dynamic labels in wpf forms & windows form

Hello everyone!!!

This is my first blog post and I’m going to share my experience on dynamic labels with you.
When we develop a system before we staring code we design interfaces. There we add buttons, labels, text boxes, radio buttons, panels, tabs and many more controls to our interface. Have you ever try out to add those controls at runtime?

Let’s think about a scenario that you want to display something on a label when system running. Here you cannot add label before run the system and make it visible false because you do not know how many labels that you need.

Solution is…………DYNAMIC CONTROLS
You can add any number of dynamic controls such as dynamic labels, text boxes etc.

Add a dynamic label to a wpf form

Label dynamiclabel = new Label();// create a new label

dynamiclabel.Width = 100; // label width
               
dynamiclabel.Margin = new Thickness(x, y, p, q); //label location

dynamiclabel.Name = "dynamiclblA"; // label id

dynamiclabel.Content = "Label created successfully"; //label content

cnvs1.Children.Add (dynamiclabel); //add label to a canvas
When we consider about the parameters of method Thickness


Add a dynamic label to a windows form

Label dynamicLabel = new Label();// create a new label

dynamicLabel.Width = 100; // label width

dynamicLabel.Location = new Point(x, y); // label location

dynamicLabel.Name = "lblElement"; // label name

dynamicLabel.Text = "dynamic label created"; // label text

tabPage2.Controls.Add (dynamicLabel); // add label to a tab pane

dynamicLabel.BringToFront();

When we consider about the parameters of method Point
 


Hope this post will help to you.
Don’t forget to leave a comment. Your suggestions are highly welcome.
Cheers!!!   

0 comments:

Post a Comment