jeudi 2 mars 2017

How do I get a list that stores different styles I.E Button , Drag&Drop etc

public partial class QuestionDragAndDropList : Form
{
    private List<ListQuestions> Questions = new List<ListQuestions>();
    private int i = 0;


    public QuestionDragAndDropList()
    {
        InitializeComponent();
        NextQuestion();
    }

    private void QuestionList()
    {
        Questions.Add(new ListQuestions("Question 1", new[] {//Answers}, 0));
        Questions.Add(new ListQuestions("Question 2", new[] {//^}, 0));
        Questions.Add(new ListQuestions("Question 3", new[] {//^}, 0));
        Questions.Add(new ListQuestions("Question 4", new[] {//^}, 0));
    }

    private void NextQuestion()
    {

        if (i != 2)
        {
            lblQuestion.Text = Questions[i].GetQuestion();
            string[] Ans = Questions[i].GetAns();
            BtnA1.Text = Ans[0];
            BtnA2.Text = Ans[1];
            BtnA3.Text = Ans[2];
            BtnA4.Text = Ans[3];
        }
        else
        {
            Questions[i].GetQuestion();
            BitMap[] Ans = Questions[i].GetAnswers();
        }
    }

    private void AnsCheck(int Answer)
    {
        if (Answer < Questions.Count)
        {
            WelcomeYear11.Userfiling.IncreaseS(); 
        }
        i++;
        if (i != Questions.Count)
        {
            NextQuestion();
        }
        else
        {
            do something.
        }
    }

    private void GrabLabel(object sender, MouseEventArgs e)
    {
        Label selectedLbl = (Label)sender;
        selectedLbl.DoDragDrop(selectedLbl.Text, DragDropEffects.Copy);
    }
    private void AllowDragDrop(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;
    }

    private void PBox1DragDrop(object sender, DragEventArgs e)
    {
        string result = e.Data.GetData(DataFormats.Text).ToString();
        if (result == "9")
        {
            lblA1.Visible = false;
            PboxA1.Visible = false;
        }
    }

    private void PBox2DragDrop(object sender, DragEventArgs e)
    {
        string result = e.Data.GetData(DataFormats.Text).ToString();
        if (result == "30")
        {
            LblA2.Visible = false;
            PBoxA2.Visible = false;
        }
    }

    private void PBox3DragDrop(object sender, DragEventArgs e)
    {
        string result = e.Data.GetData(DataFormats.Text).ToString();
        if (result == "5")
        {
            LblA3.Visible = false;
            PBoxA3.Visible = false;
        }
    }

    private void PBox4DragDrop(object sender, DragEventArgs e)
    {
        string result = e.Data.GetData(DataFormats.Text).ToString();
        if (result == "18")
        {
            LblA3.Visible = false;
            PBoxA3.Visible = false;
        }
    }
}

So using this code how am i able to not only have it set to generate forms with button questions but also with drag/drop, checkboxes, etc... The ListClass used in the sample is:

class ListQuestions {

    private string Questions; 
    private Bitmap[] Answers; private string[] Ans; //First is for Picbox questions. Second is for button questions.
    private int PosOfAns; 

    public ListQuestions(string questions, Bitmap[] answers, int posOfAns)
    {
        Questions = questions;
        Answers = answers;
        PosOfAns = posOfAns;
    }
    public ListQuestions(string questions, string[] ans, int posOfAns)
    {
        Questions = questions;
        Ans = ans;
        PosOfAns = posOfAns;
    }

    public string GetQuestion()
    {
        return Questions;
    }
    public string[] GetAns()
    {
        return Ans;
    }

    public Bitmap[] GetAnswers()
    {
        return Answers;
    }

    public int GetPosOfAns()
    {
        return PosOfAns;
    }
}

Any help is much appreciated :).




Aucun commentaire:

Enregistrer un commentaire