Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a form with a group box, titled \"Method\", containing two radio buttons.

ID: 3768184 • Letter: C

Question

Create a form with a group box, titled "Method", containing two radio buttons. These buttons should be titled "Additive" and "Subtractive". When Additive is selected, the form should display a group box titled "Additive, and it should contain three checkboxes titled Red, Blue, and Green. When Subtractive is selected, the form should display a group box titled "Subtractive, and it should contain three checkboxes titled Cyan, Yellow, and Magenta. Only one of the Additive or Subtractive group boxes should appear at any given time, and they should be in the same location on the form. You may choose to have a single group box and change the titles or you may have two different group boxes and sets of checkboxes, and make some invisible. There should also be on the form a multi-line text box. The box will not contain any text, it will just display a background color as follows: If Additive is selected, then the color should be displayed according to the chart below. The color should update at any change to any control. If Subtractive is selected, then the color should be displayed according to the chart below. The color should update at any change to any control When the user selects the Additive or Subtractive radio button, the initial state of the checkboxes may be whatever you wish.

Explanation / Answer

Tips:

I assume IDE being used by you is Visual Studio.

1. Creating a form in C#: You can create a Windows Form Application in C# by following the sequence - File -> New -> Project. This will open 'New Project' dialog box. In this dialog box, select Visual C# -> Windows Forms Application. Then specify the name of solution and press OK. This will create a blank Windows form.

Set Text property of form to "Method Form" to set the title of form window.

2. Creating group box with radio buttons: From Toolbox, select GroupBox control under Containers section and put it on form. Specify the caption "Method" under Text property of GroupBox. Now drag-n-drop two radio buttons from Toolbox under Common Tools section and put them inside the GroupBox entitled "Method". Set the Text properties of both button to "Additive" and "Subtractive" respectively.

3. Creating other group box with three check boxes: Now similarly create another GroupBox and three check boxes inside this. Initial values for Text properties of these will be as:

a) GroupBox Text: Additive

b) First check box Text: Red

c) Second check box Text: Green

d) Third check box Text: Blue

Set initial value to Visible property of Additive GroupBox to false. This will be made visible, when Additive radio button in Method GroupBox is selected and will be renamed to Subtractive, when Subtractive radio button is selected. Correspondingly, check boxes inside it will also be renamed to "Cyan", "Yellow" and "Magenta" respectively.

4. Adding multi-line text box: Drag-n-Drop a Text Box from Toolbox under Common Tools section to the form. Set Multilne property of text box to True. Initial background color of this text box is Black which is set through BackColor property of text box.

Final form design code after this step is:

-----------------------------------------

namespace MethodForm
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.radioButton1 = new System.Windows.Forms.RadioButton();
            this.radioButton2 = new System.Windows.Forms.RadioButton();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.checkBox1 = new System.Windows.Forms.CheckBox();
            this.checkBox2 = new System.Windows.Forms.CheckBox();
            this.checkBox3 = new System.Windows.Forms.CheckBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.radioButton2);
            this.groupBox1.Controls.Add(this.radioButton1);
            this.groupBox1.Location = new System.Drawing.Point(19, 29);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(230, 151);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Method";
            //
            // radioButton1
            //
            this.radioButton1.AutoSize = true;
            this.radioButton1.Location = new System.Drawing.Point(25, 31);
            this.radioButton1.Name = "radioButton1";
            this.radioButton1.Size = new System.Drawing.Size(63, 17);
            this.radioButton1.TabIndex = 0;
            this.radioButton1.Text = "Additive";
            this.radioButton1.UseVisualStyleBackColor = true;
            //
            // radioButton2
            //
            this.radioButton2.AutoSize = true;
            this.radioButton2.Location = new System.Drawing.Point(25, 55);
            this.radioButton2.Name = "radioButton2";
            this.radioButton2.Size = new System.Drawing.Size(79, 17);
            this.radioButton2.TabIndex = 1;
            this.radioButton2.TabStop = true;
            this.radioButton2.Text = "Subtractive";
            this.radioButton2.UseVisualStyleBackColor = true;
            //
            // groupBox2
            //
            this.groupBox2.Controls.Add(this.checkBox3);
            this.groupBox2.Controls.Add(this.checkBox2);
            this.groupBox2.Controls.Add(this.checkBox1);
            this.groupBox2.Location = new System.Drawing.Point(283, 31);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(230, 151);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Additive";
            this.groupBox2.Visible = false;
            //
            // checkBox1
            //
            this.checkBox1.AutoSize = true;
            this.checkBox1.Location = new System.Drawing.Point(23, 29);
            this.checkBox1.Name = "checkBox1";
            this.checkBox1.Size = new System.Drawing.Size(46, 17);
            this.checkBox1.TabIndex = 0;
            this.checkBox1.Text = "Red";
            this.checkBox1.UseVisualStyleBackColor = true;
            //
            // checkBox2
            //
            this.checkBox2.AutoSize = true;
            this.checkBox2.Location = new System.Drawing.Point(23, 54);
            this.checkBox2.Name = "checkBox2";
            this.checkBox2.Size = new System.Drawing.Size(55, 17);
            this.checkBox2.TabIndex = 1;
            this.checkBox2.Text = "Green";
            this.checkBox2.UseVisualStyleBackColor = true;
            this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
            //
            // checkBox3
            //
            this.checkBox3.AutoSize = true;
            this.checkBox3.Location = new System.Drawing.Point(23, 80);
            this.checkBox3.Name = "checkBox3";
            this.checkBox3.Size = new System.Drawing.Size(47, 17);
            this.checkBox3.TabIndex = 2;
            this.checkBox3.Text = "Blue";
            this.checkBox3.UseVisualStyleBackColor = true;
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(108, 220);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(293, 42);
            this.textBox1.TabIndex = 2;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(556, 312);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "Method Form";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.RadioButton radioButton2;
        private System.Windows.Forms.RadioButton radioButton1;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.CheckBox checkBox3;
        private System.Windows.Forms.CheckBox checkBox2;
        private System.Windows.Forms.CheckBox checkBox1;
        private System.Windows.Forms.TextBox textBox1;
    }
}

----------------------------------------

5. Displaying "Additive" GroupBox on selecting "Additive" radio button: This can be done by setting Visible property of Additive GroupBox to true. To add necessary code, double click on corresponding control in design view of form.

5. Displaying "Subtractive" GroupBox on selecting "Subtractive" radio button: Under this action, Additive GroupBox and checkboxes inside this will be renamed as described above and made visible. Also, background color of text box is changed to white. To add necessary code, double click on corresponding control in design view of form.

7. Setting background color of text box: To set background color of text box, set BackColor property of it to desired color. Correcponding code to set bacground color of text box as per states of check boxes is given below:

----------------------------------

private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Black;
                }
                else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Blue;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Green;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Cyan;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Red;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Magenta;
                }
                else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Yellow;
                }
                else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.White;
                }
            }
            else if (radioButton2.Checked)
            {
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.White;
                }
                else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Magenta;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Yellow;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Red;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Cyan;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Blue;
                }
                else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Green;
                }
                else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Black;
                }
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            groupBox2.Text = "Additive";
            checkBox1.Text = "Red";
            checkBox2.Text = "Green";
            checkBox3.Text = "Blue";
            if (radioButton1.Checked)
            {
                groupBox2.Visible = true;
            }

            if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Black;
            }
            else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Blue;
            }
            else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Green;
            }
            else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Cyan;
            }
            else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Red;
            }
            else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Magenta;
            }
            else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Yellow;
            }
            else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.White;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            groupBox2.Text = "Subtractive";
            checkBox1.Text = "Cyan";
            checkBox2.Text = "Yellow";
            checkBox3.Text = "Magenta";
            //textBox1.BackColor = Color.White;
            if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.White;
            }
            else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Magenta;
            }
            else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Yellow;
            }
            else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Red;
            }
            else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Cyan;
            }
            else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Blue;
            }
            else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
            {
                textBox1.BackColor = Color.Green;
            }
            else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
            {
                textBox1.BackColor = Color.Black;
            }
        }
  
        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Black;
                }
                else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Blue;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Green;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Cyan;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Red;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Magenta;
                }
                else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Yellow;
                }
                else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.White;
                }
            }
            else if(radioButton2.Checked)
            {
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.White;
                }
                else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Magenta;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Yellow;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Red;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Cyan;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Blue;
                }
                else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Green;
                }
                else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Black;
                }
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if(radioButton1.Checked)
            {
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Black;
                }
                else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Blue;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Green;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Cyan;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Red;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Magenta;
                }
                else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Yellow;
                }
                else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.White;
                }
            }
            else if (radioButton2.Checked)
            {
                if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.White;
                }
                else if (!checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Magenta;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Yellow;
                }
                else if (!checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Red;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Cyan;
                }
                else if (checkBox1.Checked && !checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Blue;
                }
                else if (checkBox1.Checked && checkBox2.Checked && !checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Green;
                }
                else if (checkBox1.Checked && checkBox2.Checked && checkBox3.Checked)
                {
                    textBox1.BackColor = Color.Black;
                }
            }
        }

------------------------------------------------

Above mentioned code is the final code for CheckedChanged events of all controls (radio buttons, check boxes). Background color of text box will be as per the current checked state of check boxes.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote