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

C#自学之路21

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

标签:背景色   文本框   字母   

21.文本框控件

  TextBox是最常用的和最简单的文本显示和输入控件。

   1.常用属性。

a.Text属性。显示的文本,通过TextAlign设置文本对齐方式。

b.BackColor属性。设定文本框的背景色。

c.ForeColor属性,设定文本框的前景色。

d.Font属性,设定字体的属性。

e.PasswordChar属性,输入的字母会被指定字符屏蔽。

f.Enable和Visible属性。

g.Readonly属性,是否只读。

h.MultiLine属性,是否包含多行。


  2.常用的方法。

a.Clear方法,清楚文本框中的文本。

b.AppendText方法,在文本的最后追加文本。


  3.常用的事件。


a.TextChanged事件。当文本的内容发生变化时,触发该事件。

b.Enter事件,当文本框获得焦点,触发该事件。

c.Leave事件,当文本框失去焦点,触发该事件。


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 WindowsFormsApplication6

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }


        private void textBox1_TextChanged(object sender, EventArgs e)

        {

            this.label1.Text = this.textBox1.Text;

        }


        private void textBox2_TextChanged(object sender, EventArgs e)

        {


        }


        private void Form1_Load(object sender, EventArgs e)

        {

            this.textBox1.ForeColor = Color.Blue;

            this.textBox1.BackColor = Color.White;

            this.textBox2.ForeColor = Color.Green;

            this.textBox2.BackColor = Color.White;

            this.textBox2.ReadOnly = true;

        }


        private void textBox1_Enter(object sender, EventArgs e)

        {

            this.textBox1.Clear();

        }


        private void textBox1_Leave(object sender, EventArgs e)

        {

            this.textBox2.AppendText( this.textBox1.Text + Environment.NewLine );

        }

    }

}



技术分享

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

C#自学之路21

标签:背景色   文本框   字母   

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

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