C# MetroFramework - Labels


Metro Labels are controls used to display text.

Ability to display text is one of the most important parts of Graphical user interfaces. Texts are easy an easy form of communication and very inexpensive in terms of the computing resources they consume.

Yet they provide clear and detailed information for both the computer and humans.

Why Labels?

No. Reason
1. Labels help us display text.
2. Labels are easy to work with.

Technical Characteristics of MetroLabels

MetroLabels are defines in the MetroFramework.Controls namespace.

namespace MetroFramework.Controls

in the MetroFramework.dll assembly.

MetroLabels are Labels in that they derive from System.Windows.Forms.Label class:

public class MetroLabel : Label..{}

MetroLabels implement IMetroControl interface:

    public class MetroLabel : Label, IMetroControl{..}

Creating MetroLabels

MetroLabel class defines us one public contructor:

    public MetroLabel();

We simply create a MetroLabel using:

    MetroLabel myLabel = new MetroLabel ();

Setting MetroLabel Properties

MetroLabel provides us several properties we can use to influence the visual aspects of the control e.g

Setting MetroLabel Text

For example we can set Text using:

    MetroLabel myLabel = new MetroLabel { Text = "Free Will vs Determinism"};

Setting MetroLabel Location

That is location in the form:

    MetroLabel myLabel = new MetroLabel { Location = new System.Drawing.Point(232, 210)};

AutoSizing AutoLabel

AutoSizing it according to the text to be rendered:

    MetroLabel myLabel = new MetroLabel { AutoSize = true};

Full MetroLabel Example

Here's a full example with a Metrolabel inside a MetroForm:

using System;
using System.Windows.Forms;
using MetroFramework.Controls;
using MetroFramework.Forms;

namespace MyMetroForm
{
    static class Program
    {
        public static void Main()
        {
            MetroForm myForm = new MetroForm
            {
                Text = "MetroForm Example",
                ClientSize = new System.Drawing.Size(564, 420),
            };
            MetroLabel myLabel = new MetroLabel { Location = new System.Drawing.Point(232, 210), Text = "Free Will vs Determinism",AutoSize = true};

            myForm.Controls.Add(myLabel);
            Application.Run(myForm);
        }
    }
}

Result:

MetroForm MetroLabel

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post