日期:2014-05-17  浏览次数:20926 次

当鼠标单击按钮时,按钮上的内容出现在文本框中,再次单击文本框内容消失
当鼠标单击按钮时,按钮上的内容出现在文本框中,再次单击文本框内容消失.
------最佳解决方案--------------------
 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;
        }

------其他解决方案--------------------
同意楼上的方法。