Set Label Background, foreground color and border style : Label « GUI Windows Form « C# / C Sharp






Set Label Background, foreground color and border style

Set Label Background, foreground color and border style
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
      private System.Windows.Forms.Button learnMoreButton;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Label label1;
      
      public Form1() {
        InitializeComponent();
      }

      private void InitializeComponent()
      {
         this.learnMoreButton = new System.Windows.Forms.Button();
         this.label2 = new System.Windows.Forms.Label();
         this.label1 = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // learnMoreButton
         // 
         this.learnMoreButton.Font = new System.Drawing.Font( "Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
         this.learnMoreButton.Location = new System.Drawing.Point( 17, 81 );
         this.learnMoreButton.Name = "learnMoreButton";
         this.learnMoreButton.Size = new System.Drawing.Size( 120, 59 );
         this.learnMoreButton.TabIndex = 11;
         this.learnMoreButton.Text = "Learn More";
         // 
         // label2
         // 
         this.label2.BackColor = System.Drawing.Color.LightYellow;
         this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
         this.label2.Font = new System.Drawing.Font( "Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
         this.label2.ForeColor = System.Drawing.Color.MidnightBlue;
         this.label2.Location = new System.Drawing.Point( 17, 154 );
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size( 273, 25 );
         this.label2.TabIndex = 10;
         this.label2.Text = "text";
         this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         // 
         // label1
         // 
         this.label1.BackColor = System.Drawing.Color.LightYellow;
         this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
         this.label1.Font = new System.Drawing.Font( "Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
         this.label1.ForeColor = System.Drawing.Color.MidnightBlue;
         this.label1.Location = new System.Drawing.Point( 17, 17 );
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size( 273, 47 );
         this.label1.TabIndex = 9;
         this.label1.Text = "test";
         this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         // 
         // VisualInheritanceForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size( 307, 201 );
         this.Controls.Add( this.learnMoreButton );
         this.Controls.Add( this.label2 );
         this.Controls.Add( this.label1 );
         this.Name = "VisualInheritanceForm";
         this.Text = "Visual Inheritance";
         this.ResumeLayout( false );

      }

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }

}



           
       








Related examples in the same category

1.Label: Localtion, Name, Size, TabIndex, Text
2.Add image to Label and set ImageAlign to MiddleRightAdd image to Label and set ImageAlign to MiddleRight
3.Label grows as the inner textLabel grows as the inner text
4.Label auto resizeLabel auto resize
5.Marquee Label HostMarquee Label Host
6.Use Label and Timer to create a Clock