jeudi 31 mars 2016

i cant get my check boxes to show that they checked when i open the saved file

I dont understand why my save and open dont work with the check boxes any advice would be great i have three check boxes Nuts Cherries and Sprinkles

i also have to have the check boxes revert back to the original saved file as well`

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
    int savedIndex = 0;

    public Form1()
    {
        //index for flavor of icecream
        InitializeComponent();
        flavorBox.SelectedIndex = 0;
        syrupBox.SelectedIndex = 0;
        pictureBox1.Image = Properties.Resources.Vanilla;
    }
    // my save fucntion
    private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        StreamWriter sw;

        SaveFileDialog sfd = new SaveFileDialog();

        if (sfd.ShowDialog() == DialogResult.OK)
        {
            sw = new StreamWriter(sfd.FileName);
            savedIndex = flavorBox.SelectedIndex;

            sw.WriteLine(flavorBox.SelectedIndex);

            if (Nuts.Checked == true)
            {
                sw.WriteLine();

            }
           if (Cherries.Checked == true)
            {
                sw.WriteLine();
            }

            if(Sprinkles.Checked == true)
            {
                sw.WriteLine();
            }

            sw.Close();
        }

    }

    private void openToolStripMenuItem_Click(object sender, EventArgs e)
    {
        StreamReader sr;
        string strInput;

        OpenFileDialog ofd = new OpenFileDialog();

        if (ofd.ShowDialog() == DialogResult.OK)
        {
            sr = new StreamReader(ofd.FileName);

            strInput = sr.ReadLine();
            savedIndex = Convert.ToInt32(strInput);
            flavorBox.SelectedIndex = savedIndex;
            syrupBox.SelectedIndex = savedIndex;

            if(Nuts.Checked == true)
                {
                sr.ReadLine();

                return;

                }
             if(Cherries.Checked == true)
            {
                sr.ReadLine();
            }

            if(Sprinkles.Checked == true)
            {
                sr.ReadLine();
            }
            sr.Close();

        }

    }

    private void revertToolStripMenuItem_Click(object sender, EventArgs e)
    {
        flavorBox.SelectedIndex = savedIndex;
        syrupBox.SelectedIndex = savedIndex;

    }

    private void closeToolStripMenuItem_Click(object sender, EventArgs e)
    {

        Close();
    }

    private void flavorBox_SelectedIndexChanged(object sender, EventArgs e)
    {
        int index = flavorBox.SelectedIndex;

        if (index == 0)
        {
            pictureBox1.Image = Properties.Resources.Vanilla;
        }
        else if (index == 1)
        {
            pictureBox1.Image = Properties.Resources.Chocolate;
        }
        else if (index == 2)
        {
            pictureBox1.Image = Properties.Resources.strawberry;
        }

    }

    private void Nuts_CheckedChanged(object sender, EventArgs e)
    {
        Nuts.Items.Add(true)// i tried this one on this site that found doesnt work though
    }
}

}




Aucun commentaire:

Enregistrer un commentaire