如何在c#中保存带文本框的复选框 [英] how to save checkbox with textbox in c#
本文介绍了如何在c#中保存带文本框的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个复选框,旁边是一个文本框,现在我想保存文本框的值,如果选中复选框,如果不是按钮保存。你能否展示一些代码....
I have a checkbox and beside of it is a textbox, now i want to save the value of textbox if the checkbox is check and if not dont save by a button. Can you show some codes please....
推荐答案
第1步:
创建保存方法< br $>
step 1:
create save method
private void SaveData()
{
if(checkbox.Checked)
{
//write save process codes
}
}
< br $>
第2步:
在复选框中调用save方法CheckedChanged事件
step 2:
call the save method in check box CheckedChanged event
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
SaveData();
}
首先,您需要决定保存哪个事件。更改检查或单击按钮时。然后你想把它保存到文件,数据库或其他地方。
假设它是一个按钮点击事件并保存到一个名为的文件和方法中SaveText():
你只需要在checkbox.Checked为true时进行测试
First you need to decide on what event will it be saved. Either when check changed or button was clicked. Then where/how you want to save it- to a file, database or other.
assume it is a button click event and saved to a file and method called is SaveText():
you only need to test for when checkbox.Checked is true
void SaveText()
{
string txt = textbox.Text;
if(checkbox.Checked){
// save to file
}
// else do nothing
}
这篇关于如何在c#中保存带文本框的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文