Code
Code
Q. Choose one of the class and mark from the semester checkbox
and show the subjects about that class of semester
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WF01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void setItems()
{
listBox1.Items.Clear();
if (radioButton1.Checked)
{
if (checkBox1.Checked == true)
{
listBox1.Items.Add("Subjects of MCS Semester-I");
listBox1.Items.Add("Programming Fundamentals");
listBox1.Items.Add("DLD");
listBox1.Items.Add("OS");
listBox1.Items.Add("DBMS");
listBox1.Items.Add("BC");
listBox1.Items.Add("Islamiat");
}
if (checkBox2.Checked == true)
{
listBox1.Items.Add("Subjects of MCS Semester-II");
listBox1.Items.Add("SE-I");
listBox1.Items.Add("Java");
listBox1.Items.Add("Web");
listBox1.Items.Add("DDBMS");
listBox1.Items.Add("DS");
listBox1.Items.Add("DCN");
}
}
else if (radioButton2.Checked)
{
if (checkBox1.Checked == true)
{
listBox1.Items.Add("Subjects of BSCS Semester-I");
listBox1.Items.Add("Intro to Computing");
listBox1.Items.Add("Fundamentals of Algorithm");
listBox1.Items.Add("English Comprehension");
listBox1.Items.Add("Calculus-I");
listBox1.Items.Add("Accounting");
listBox1.Items.Add("Islamiat & Pak Studies");
}
if (checkBox2.Checked == true)
{
listBox1.Items.Add("Subjects of BSCS Semester-II");
listBox1.Items.Add("Programming Fundamentals");
listBox1.Items.Add("DCN");
listBox1.Items.Add("Calculus-II");
listBox1.Items.Add("BC");
listBox1.Items.Add("DBMS");
listBox1.Items.Add("Web");
}
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
setItems();
}
Q. Write text in the textbox that will add text into listbox on clicking
the Add item button, count item in the listbox on clicking the count
button, Show Item names that in listbox on the MessageBox by
clicking on the Show Item button.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Add_Items_Listbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
listBox1.Items.Add(textBox1.Text);
textBox1.Clear();
}
Q. Write Number in the textbox and show the even number in the
listbox and the odd number in the (multiline textbox) textbox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Even_Odd
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
else if(a % 2==1)
{
textBox2.AppendText(a+"\n");
}
}
}
}
Q. How to make a textbox to MultiLine
Q. Write number in the textbox and show their table in the listbox and
the textbox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Table
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Q.Write Text in the textbox and add that text into the listbox and then
select item from listbox and add it into the multiline textbox
Textbox Scrollbar
For set scrollbar in the textbox then go to in the properties of textbox and change the
scrollbars settings of the textbox as n the picture its set as vertical.
Listbox Scrollbar
For listbox to set scroll bar then go into the properties of listbox and set the
ScrollbarAlwaysVisible =True
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ListBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
textBox1.Clear();
}
Q. Program to give user name and password to get login if the user
name and password true then a message box will appear and show
you are granted access and after click on the ok button of the
Message Box a New Form will appear on the screen if the password is
not correct then the Application is exit after 3 tries.
For save username and password we use the tag property of the textbox to save the
user name and password in tag property as you see in the above GUI or pictures.
For Add new form we do this process as see in the below picture
After doing this see the step in the below picture for to Add form
First we do to true the enabled property of timer and Second we set timer interval
property like in the above picture wee set interval property is 400.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ChangeForm
{
public partial class Form1 : Form
{
int atempt;
public Form1()
{
InitializeComponent();
atempt = 1;
}
if (label1.Visible)
label1.Visible = false;
else
label1.Visible = true;
}
}
}
Q. Program to Show Current Time in the Textbox and Also Show the
Day and Date in the Textbox
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox2.Text = DateTime.Now.ToLongDateString();
textBox3.Text = DateTime.Now.ToShortDateString();
textBox4.Text = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" +
DateTime.Now.Year;
}