Exemplo n.º 1
0
        public Examenes()
        {
            InitializeComponent();
            this.CenterToScreen();

            // StartPosition was set to FormStartPosition.Manual in the properties window.
            Rectangle screen = Screen.PrimaryScreen.WorkingArea;
            int       w      = Width >= screen.Width ? screen.Width : (screen.Width + Width) / 2;
            int       h      = Height >= screen.Height ? screen.Height : (screen.Height + Height) / 2;

            this.Location = new Point((screen.Width - w) / 2, (screen.Height - h) / 2);
            this.Size     = new Size(657, h);

            foreach (Label lbl in this.Controls.OfType <Label>())
            {
                lbl.BackColor = Color.Transparent;
            }
            this.CenterToScreen();                             //Inicializamos y lo centramos a pantalla

            Examen exam = new Examen();                        //Creamos nuevo objeto de la clase examen

            exam.RellenarListas();                             //Ejecutamos el constructor
            usrlvl = exam.usrlvl;
            List <string>         preguntas  = exam.preguntas; //Asociamos las preguntas, respuestas e ids correspondientes totales
            List <string>         respuestas = exam.respuestas;
            List <string>         Ides       = exam.Id_preguntas;
            List <List <string> > dupla      = new List <List <string> >();         //Creamos una lista de listas

            dupla                = exam.Randomize(10, preguntas, respuestas, Ides); //Ahora aleatorizamos las preguntas
            preguntas            = dupla[0];                                        //Asignamos las preguntas y respuestas correspondientes
            respuestas           = dupla[1];
            Ides                 = dupla[2];
            listaIds_Contestados = Ides;
            respuestasC          = respuestas; //Asignamos la variable local a una del formulario

            //Asignamos textBox

            myTextBoxes = new TextBox[] { textBox12, textBox11, textBox10, textBox9, textBox8, textBox7, textBox6, textBox5, textBox4, textBox3 };

            //Ocultamos los textbox en caso de que la pregunta sea SI/NO
            int k = 0;

            foreach (TextBox txtb in myTextBoxes)
            {
                if (respuestasC[9 - k].Equals("Sí") || (respuestasC[9 - k].Equals("No")))
                {
                    txtb.Hide();
                }
                k++;
            }
            //Asignamos groupBox


            myGroupBoxes = new GroupBox[] { groupBox1, groupBox2, groupBox3, groupBox4, groupBox5, groupBox6, groupBox7, groupBox8, groupBox9, groupBox10 };
            int l = 0;

            foreach (GroupBox grp in myGroupBoxes)
            {
                if (!respuestasC[l].Equals("Sí") && !respuestasC[l].Equals("No"))
                {
                    grp.Hide();
                }
                l++;
            }


            //Rellenamos los labels de el formulario
            int i          = 0;
            var validItems = this.Controls.OfType <Label>().Where(j => !j.Text.Contains("Pregunta"));

            foreach (var lbl in validItems)
            {
                lbl.Text = preguntas[9 - i];
                i++;
            }
        }