关于checkbox的问题,希望各位高手帮帮忙!
我现在想用一个checkbox控件,当选中checkbox控件的时候,将事先已经填入文本框的信息显示到另外一个文本框中。请问该如何实现这一点?希望各位高手帮帮忙!!!!
------解决方案--------------------处理CheckStateChanged事件,下面是代码,我测试过了
private void checkBox1_CheckStateChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
Console.WriteLine( "true ");
textBox2.Text = textBox1.Text;
}
else
{
Console.WriteLine( "false ");
}
}
------解决方案--------------------用js实现
------------------
<input type= "checkbox " onclick= "setValue(); ">
<input type= "text " id= "text1 ">
<input type= "text " id= "text2 " value= "value2 ">
<script type= "text/javascript ">
function setValue(){
document.getElementById( "text1 ").value=document.getElementById( "text2 ").value;
}
</script>
------解决方案--------------------private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
textBox2.Text = textBox1.Text;
}
}
------解决方案--------------------winform的,你们都弄错了
------解决方案--------------------CheckedChanged事件..
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
this.textBox2.Text = this.textBox1.Text;
}
}
------解决方案--------------------其实就用Click就可以
checkBox1.Click+=delegate
{
if(checkBox1.Checked)
{
//....
}
};
------解决方案--------------------private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
{
textBox2.Text = textBox1.Text;
}
else
{
textBox2.Text = " ";
}
}