C# MetroFramework - Labels

March 9, 2018 Oclemy C# Label 1 minute, 24 seconds

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

Comments