lundi 25 avril 2016

How can I get user input and store it as a new application setting in c#?

I'm a beginner trying to make a food randomizer, that when you click a button it gives you a new food with recipe, description, name and image if available. I have two forms, in which when you click a button in one goes to another to add a new recipe. What I'm having trouble with at the moment is how I can store the new recipes and create new ones, but not delete old ones, when clicked add recipe more than once.
If you need to see what my code looks like I'll post it.

public partial class Form1 : Form
{
    public string ingredients;
    public string descriprion;
    public string foodName;
    public Recipes recipes;
    public Form1()
    {
        InitializeComponent();
    }

    private void /*Food*/button1_Click(object sender, EventArgs e)
    {
        name.AppendText(Properties.Settings.Default.Name);
        textBox1.AppendText(Properties.Settings.Default.Ingredients);
        Description.AppendText(Properties.Settings.Default.Description);
    }

    private void /*Description*/Description_TextChanged(object sender, EventArgs e)
    {

    }

    private void /*URL*/button2_Click(object sender, EventArgs e)
    {

    }

    private void /*AddRecipe*/button1_Click_1(object sender, EventArgs e)
    {
        Recipe form2 = new Recipe();
        form2.Show();
    }

    private void /*Ingredients*/textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void/*FoodPic*/ pictureBox1_Click(object sender, EventArgs e)
    {

    }

    private void /*Name*/name_TextChanged(object sender, EventArgs e)
    {

    }

}

public partial class Recipe : Form { Form1 form1 = new Form1();

    public Recipe()
    {
        InitializeComponent();
    }

    private void /*Ingredients*/textBox2_TextChanged(object sender, EventArgs e)
    {

        var recipes = new Recipes();
        recipes.RecipesIngredients = textBox2.Text;
        Properties.Settings.Default.Ingredients = recipes.RecipesIngredients;
        Properties.Settings.Default.Save();
    }

    private void /*Name*/textBox3_TextChanged(object sender, EventArgs e)
    {
        var recipes = new Recipes();
        recipes.RecipesName = textBox3.Text;
        Properties.Settings.Default.Name = recipes.RecipesName;
        Properties.Settings.Default.Save();

    }

    private void /*Description*/textBox1_TextChanged(object sender, EventArgs e)
    {
        var recipes = new Recipes();
        recipes.RecipesDescription = textBox1.Text;
        Properties.Settings.Default.Description = recipes.RecipesDescription;
        Properties.Settings.Default.Save();

    }

}

 /*other class for the recipes*/ public class Recipes
{
    public Recipes() { }
    public string RecipesDescription { get; set; }
    public string RecipesName { get; set;}
    public string RecipesIngredients { get; set;}
}    




Aucun commentaire:

Enregistrer un commentaire