如果我必须实现保存和编辑按钮,我该怎么办? [英] What should I do if I have to implement a save and edit button?
问题描述
你好,
我正在创建一个表单,我有一些TextBoxes。我想将数据保存到文本文件(我已经这样做了)。当我点击保存按钮时,它会将数据保存到文件中,然后将按钮文本更改为编辑(我已完成此操作)。
现在,点击保存按钮后,我希望禁用TextBoxes,当我点击编辑按钮时,它将重新启用。如果TextBox中的数据被更改,那么它将要求确认保存,否则它将显示没有进行任何更改并覆盖现有文件。
请帮助。
我尝试了什么:
我已经拿了两个保存按钮,两个编辑按钮和值的变化我采取了两个TextBox并比较它们。但我觉得这不对。我不想要两个控件。
Hello,
I am creating a form and I have a few TextBoxes. I want to save the data to a text file (I have already done that). When I click on the "Save" button, it will save the data to a file and then change the button text to "Edit" (I have done this).
Now, after clicking on the save button, I want the TextBoxes to be disabled and when I click on the edit button, it will re-enable. If the data in the TextBoxes is changed then it will ask for confirmation for saving, else it will show no changes made and overwrite the existing file.
Please help.
What I have tried:
I have taken two save buttons, two edit buttons and for the value change I have taken two TextBoxes and comparing them. But I feel that this is not right. I don't want two of each controls.
推荐答案
这是Windows Forms,你可以使用Control.Enabled Property(System.Windows.Forms) [ ^ ]启用或禁用控件。
编辑后的数据是什么。在程序中添加一个新的布尔变量,例如
Taken this is Windows Forms, you can use Control.Enabled Property (System.Windows.Forms)[^] to enable or disable the control.
What comes to the edited data. Add a new boolean variable to your program, for example
bool changesSaved;
保存更改后,将其设置为 true
。还连接 Control.TextChanged事件(系统。 Windows.Forms) [ ^ ]并在该事件中将 changesSaved
设置为 false
。现在需要时,您可以调查ig更改是否已更改。只需记住正确设置初始值,例如,如果您从文件中读取数据。
Once you save the changes, set it to true
. Also wire Control.TextChanged Event (System.Windows.Forms)[^] and in that event set the changesSaved
to false
. Now when needed you can investigate ig the changes have been changed or not. Just remember to set the initial value correctly for example if you read the data from a file.
这篇关于如果我必须实现保存和编辑按钮,我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!