C# Label和LinkLabel

         在 Windows 窗体应用程序中,标签控件王要分为普通的标签 (Label) 和超链接形式的标签 (LinkLabel) 。

普通标签 (Label) 和超链接标签控件 (LinkLabel)控件的常用属性如下表所示:

                           

            普通标签控件 (Label) 中的事件与窗体的事件类似,

     常用的事件主要有鼠标单击事件、 鼠标双击事件、标签上文本改变的事件等。

             超链接标签(linkLabel)主要应用的事件是鼠标单击事件,通过单击标签完成不同的操作,

      例如在 QQ 窗体中注册账号和找回密码的操作。

【实例】

               创建一个窗体,在窗体上放置两个普通标签控件 (Label),分别显示“早上好!”和“GoodMorning!”。

        在窗体上通过单击超链接标签 (LinkLabel) 交换这两个标签上显示的信息。

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LabelAndLinkLabel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //超链接标签控件的单击事件
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //交换标签上的信息
            string temp = label1.Text;
            label1.Text = label2.Text;
            label2.Text = temp;
        }      
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace LabelAndLinkLabel
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

                                  

                                  

猜你喜欢

转载自blog.csdn.net/zs1342084776/article/details/91410711