C#课后题---文本框实例

来源:互联网 发布:淘宝店转让4个钻多少钱 编辑:程序博客网 时间:2024/05/22 14:43

   题目要求:

       窗体上有一个文本框(多行、且带有垂直滚动条)、一个标签(字体颜色红色、字号16)、一个按钮(该按钮被单击时,实现将文本框中选择文本复制至标签。

    输入代码:

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 WindowsFormsApplication5{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {        }        private void textBox1_TextChanged(object sender, EventArgs e)        {        }        private void button1_Click(object sender, EventArgs e)        {            label1.Text = textBox1.SelectedText;        }    }}

运行截图:





总结:

 主要运用了TextBox相关的知识点,难点在于如何把单行文本变成多行文本,我的办法是这样的:设置文本框属性,先把Multiline属性改为true,然后再把ScrollBars属性改为Vertical。其次是Click单击事件,直接属性传值就OK了。

0 0
原创粉丝点击