C#如何保存我编辑过窗口表单的用户数据 [英] C# how to save user's data which I have edited windows forms

查看:171
本文介绍了C#如何保存我编辑过窗口表单的用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单上我只有显示全部按钮,当我点击它时,它在FlowLayoutPanel中显示我的用户数据,我必须删除或编辑我的用户。我已经写了删除按钮的功能,当我点击编辑按钮时右上角打开Panel,其中有3个文本框名称,姓氏,年龄和保存按钮。当我点击面板中的编辑按钮时,显示该用户的数据,我需要编辑它并单击保存按钮。之后在FlowLayoutPanel中应该显示用户已经编辑过。我怎么能这样做?



我尝试过:



On form i have only Show All Button, when i click on it, it shows me my user's data in FlowLayoutPanel,i must delete or edit my users.I have written function for delete button,when i click on edit button in the right corner opens Panel which has 3 textbox`Name,Last Name,Age and Save Button.When i click on edit button in Panel shows me that user's data and i need to edit it and click on Save button.After that in FlowLayoutPanel should show that user already edited.How can i do it?

What I have tried:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    public void Sharel()
    {
        flowLayoutPanel2.Controls.Clear();
        foreach(User item in Controller.users)
        {
            FlowLayoutPanel flp = new FlowLayoutPanel();
            flp.BackColor = Color.Cyan;
            Label lb = new Label();
            lb.Text = item.name;
            lb.ForeColor = Color.White;
            lb.Font = new Font("Verdana", 10);
            Label lb1 = new Label();
            lb1.Text = item.age.ToString() + " years old";
            lb1.ForeColor = Color.White;
            lb1.Font = new Font("Verdana", 10);
            Label lb2 = new Label();
            lb2.Text = item.lastname;
            lb2.ForeColor = Color.White;
            lb2.Font = new Font("Verdana", 10);
            flp.Controls.Add(lb);
            flp.Controls.Add(lb2);
            flp.Controls.Add(lb1);
            Button bt = new Button();
            bt.Text = "Delete";
            flp.Controls.Add(bt);
            bt.Click += new EventHandler(delete);
            flowLayoutPanel2.Controls.Add(flp);
            bt.Tag = item.id.ToString();
            Button b = new Button();
            b.Text = "Edit";
            flp.Controls.Add(b);
            b.Click += new EventHandler(edit);
            b.Tag = item.id.ToString();
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.Sharel();
    }
    public void delete(object sender, EventArgs e)
    {
        Button ays = (Button)sender;
        Controller.users = Controller.users.FindAll(item => item.id.ToString() != ays.Tag.ToString());
        this.Sharel();
        //MessageBox.Show(ays.Tag.ToString(), "Jnjvac e");
    }
    public void edit(object sender, EventArgs e)
    {
        Button ayn = (Button)sender;
        panel1.Visible = true;
        User x = Controller.users.Find(item => item.id.ToString() == ayn.Tag.ToString());
        textBox1.Text = x.name;
        textBox2.Text = x.age.ToString();
        textBox3.Text = x.lastname;

    }
}

推荐答案

最简单的方法是保存数据(大概是在某些描述的数据库),当返回到父级时,只需重新加载所有数据。



BTW,您应该使用设计器来指定控件属性(如字体系列,大小和颜色),因为那个废话只会使支持代码混乱。
The simplest method is to save the data (presumably in a database of some description), and when returning to the parent for, simply reload all the data again.

BTW, you should use the designer to specify control properties (like font family, size, and color), because that crap just clutters up the supporting code.


这篇关于C#如何保存我编辑过窗口表单的用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆