码迷,mamicode.com
首页 > Windows程序 > 详细

C#自学之路20

时间:2015-04-13 07:08:10      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:背景图片   标签   背景色   

20.标签控件

  标签主要用来显示文本,还可以显示图片,虽然参与窗口的Tab键顺序,但不接受焦点。

  1.常用属性。

a.Text属性,显示文本,可以用TextAlign设置文本对其方式。

b.BorderStyle属性,设定标签的边框形式。

c.BackColor属性,设定标签的背景色。

d.ForeColor属性,设定标签的前景色。

e.Font属性,设置字体的各种属性。

f.Image属性,设定标签的背景图片。

g.Enable和Visible,可用和可见属性。

h.AutoSize,设定控件根据文本调整。



using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;


namespace WindowsFormsApplication4

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            this.label1.AutoSize = true;

            this.label1.BackColor = Color.White;

            this.label1.Text = "宋体9号,白底黑字!";


            this.label2.AutoSize = true;

            this.label2.BackColor = Color.Black;

            this.label2.Font = new Font( "宋体",10.5F,FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)) );

            this.label2.ForeColor = Color.White;

            this.label2.Text = "宋体10号,黑底白字!";


            this.label3.AutoSize = true;

            this.label3.BackColor = Color.Blue;

            this.label3.Font = new Font( "楷体_GB2312",14.25F,FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)) );

            this.label3.ForeColor = Color.Red;

            this.label3.Text = "楷体14号,蓝底红字!";

        }


        private void Form1_Click(object sender, EventArgs e)

        {

            MessageBox.Show( "单击了!","提示" );

        }


        private void Form1_DoubleClick(object sender, EventArgs e)

        {

            MessageBox.Show("双击了!", "提示");

        }


        private void label1_Click(object sender, EventArgs e)

        {

            MessageBox.Show("label单击了!", "提示");

        }


        private void label1_DoubleClick(object sender, EventArgs e)

        {

            MessageBox.Show("label双击了!", "提示");

        }

    }

}



技术分享

本文出自 “郭俊的博客” 博客,转载请与作者联系!

C#自学之路20

标签:背景图片   标签   背景色   

原文地址:http://10093949.blog.51cto.com/10083949/1631609

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!