首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

当鼠标单击按钮时,按钮下的内容出现在文本框中,再次单击文本框内容消失

2012-12-24 
当鼠标单击按钮时,按钮上的内容出现在文本框中,再次单击文本框内容消失当鼠标单击按钮时,按钮上的内容出现

当鼠标单击按钮时,按钮上的内容出现在文本框中,再次单击文本框内容消失
当鼠标单击按钮时,按钮上的内容出现在文本框中,再次单击文本框内容消失.
[最优解释]
 private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim() == "")
            {
                textBox1.Text = (sender as Button).Text;
            }
            else
            {
                textBox1.Text = "";
            }
        }
[其他解释]
if(txt1.Text=="")
{
  txt1.Text = (sender as Button).Text;
}
else
{
  txt1.Text = "";
}
[其他解释]


//只要写这一个事件就够了
        //其他按钮的Click事件选择这个事件
        private void button1_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = (sender as Button).Text;
        }

        //当控件被激活时 出发此事件
        private void textBox1_Enter(object sender, EventArgs e)
        {
            //清空文本框
            this.textBox1.Text = string.Empty;
        }

[其他解释]
同意楼上的方法。

热点排行