explen the follwing in yellow: first program: second program: I private void but
ID: 3833946 • Letter: E
Question
explen the follwing in yellow:
first program:
second program:
I private void button1 Click(object sender, EventArgs e) combo Box1.Items.Add Days") combo Box1.Items.Add Months") combo Box1.Items.Add "Years") private void comboBox1 SelectedlndexChanged(objectsender, EventAugse) if (comboBox 1.Selectedltem Days") comboBox2. Items. Clear(); comboBox2 Items,Add Saterday") combo Sunday" Monday"); comboBox2. Items Tuesday"); else if (comboBox1.Selectedltem Months") combo Box2.Items.Clear(): combo Box2.Items Add Jan") combo Box2.Items Add Feb'') March") combo Box2.Items April" else if (comboBox1.Selectedltem "Years") combo Box2.Items.Clear(): comboBox2. Items 2014") combo Box2.Items 2015" combo Box2.Items 2016" combo Box2.Items 2017 private void comboBox2 SelectedlndexChanged(objectsender, EventArgs e) textBox1. Text scomboBox2.Text private void button2 Click(object sender, EventAugse) The selected item textBox1.Text 'Contents Message Box Buttons,YesNoCancel);Explanation / Answer
The explanation to the yellow marked code is given as comments(Bold Text) shown below.
first Program:
/*There is ComboBox object named comboBox1. To that comboBox1 we are adding three items (Days, Months and years)*/
comboBox1.Items.Add("Days");
comboBox1.Items.Add("Months");
comboBox1.Items.Add("Years");
/* If user selectes "Days" in comboBox1 then add (Saturday,Sunday,Monday,Tuesday) to comboBox2. */
if(comboBox1.SelectedItem == "Days") {
comboBox2.Items.Add("Saturday");
comboBox2.Items.Add("Sunday");
comboBox2.Items.Add("Monday");
comboBox2.Items.Add("Tuesday");
} else if(comboBox1.SelectedItem == "Months") {
/* If user selectes "Months" in comboBox1 then add (Jan,Feb,March,April) to comboBox2. */
comboBox2.Items.Add("Jan");
comboBox2.Items.Add("Feb");
comboBox2.Items.Add("March");
comboBox2.Items.Add("April");
} else if(comboBox1.SelectedItem == "Years"){
/* If user selectes "Years" in comboBox1 then add (2014,2015,2016,2017) to comboBox2. */
comboBox2.Items.Add("2014");
comboBox2.Items.Add("2015");
comboBox2.Items.Add("2016");
comboBox2.Items.Add("2017");
}
textBox1.Text = comboBox2.Text // sets the comboBox2 value to the textBox1 (Textbox Object)
/* shows a Message box, with a message given in first parameter, Caption of the message given in second parameter with
yes , No, and Cancel Buttons */
MessageBox.Show("the selected item "+textBox1.Text + "..." + button1.Text, "Cotents", MessageBoxButtons.YesNoCancel);
// adds textBox1's value to the comboBox3's Items list.
comboBox3.Items.Add(textBox1.Text);
Second Program:
listBox1.Items.clear(); // clear the listBox. Removes all the Items from the list box
sum =0;
int S,E,P;
/* set the value of the two textboxes in varibles S and E respectively. As S and E are integer variables and textBox1.Text will return string, parse the string value to int using int.parse() function */
S= int.Parse(textbox1.Text);
E= int.Parse(textbox2.Text);
/* If S is greater than E then swap the value of S and E */
if(S>E) {
P=S;
S=E;
E=P;
}
/* if radioButton1 is checked then , starting from value stored in S, add all the values starting from (S to E) to the listBox1's Items list
example, if S= 2 and E= 5, add 2,3,4,5 to the listBox1
*/
if(radioButton1.Checked == true) { // if radioButton1 is checked then radioButton1.Checked returns true
for(int i = S; i<=E; i++) {
listBox1.Items.Add(i);
sum+= i; // sum = sum + i -- calculete the sum of all values added to the listBox1
}
}
/* finally set the value of textBox3 to the sum calculated above.
As textBox3.Text is a string and sum is a number, calling sum.ToString() returns the string */
textBox3.Text = sum.ToString();
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.