0% found this document useful (0 votes)
17 views8 pages

C sharp slybs

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views8 pages

C sharp slybs

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1: How we create a simple form in C sharp

using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
2: How we use load command in C sharp form
using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

}
}
}
3: How we make a button in C sharp form
using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{

}
}
}
4: How we show a message on clicking a
button
And change background color of a button
using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
MessageBox.Show("Hello from button 1");
button1.BackColor = Color.Aqua;
}
}
}

5: How we create as combo box in c sharp


and add elments in

using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs


e)
{

}
}
}
// By using query.

using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
comboBox1.Items.Add("Mango");
comboBox1.Items.Add("Banana");
comboBox1.Items.Add("Dates");
comboBox1.Items.Add("Apple");
comboBox1.Items.Add("Gava");
}
}
}

// by using list.

using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{

List<string> list = new List<string>()


{
"Mango","Apple","Dates","Banana","Grapes"
};
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
comboBox1.DataSource = list;
}
}
}
6: how we create a label in c sharp form
using System;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)


{

}
}
}

7: All properties of a button

8: Assignment Questions
Assignment Question

Step-1
Create a Windows Form application in C# with a TextBox control.
Implement functionality to allow users to enter text into the TextBox.
Write code to display a message box with the entered text when a button is
clicked.
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
MessageBox.Show(textBox1.Text);
}
}
}
Step-2
Extend the previous application to include validation for the TextBox.
Implement validation to ensure that the user enters a non-empty string before displaying
the message.
Show an error message if the TextBox is left empty when the button is clicked.
private void button1_Click(object sender, EventArgs e)
{
if(!(textBox1.Text.Length==0))
{
MessageBox.Show(textBox1.Text);
}
else
{
MessageBox.Show("Error! you never enter any string");
}
}

Step-3
Create a Windows Form application with two TextBox controls.
Designate one TextBox as a regular text input and the other as a password input.
Implement functionality to display the entered text in the regular TextBox and hide it with
asterisks (*) in the password TextBox.

private void button1_Click(object sender, EventArgs e)


{
textBox2.Text = textBox1.Text;
}

Step-4
Develop a Windows Form application with a multiline TextBox control.
Allow users to enter multiple lines of text.
Implement a feature to count and display the number of lines entered in a label or another
TextBox.

private void button1_Click(object sender, EventArgs e)


{
int count = textBox1.Lines.Length;
int count = textBox1.Text.Length;

MessageBox.Show("The numbers of enter lines are:" + count);


}
Step-5
Create a Windows Form application with a TextBox control and a label.
Write code to update the label text dynamically as the user types in the TextBox.
Utilize the TextChanged event to achieve this real-time update.

private void textBox2_TextChanged(object sender, EventArgs e)


{
label3.Text = textBox2.Text;
}
Step-6
Extend the previous application to include copy, cut, and paste operations for the TextBox.
Implement buttons for copy, cut, and paste and write code to perform the respective operations
using the Clipboard class.
private void textBox2_TextChanged(object sender, EventArgs e)
{
label3.Text = textBox2.Text;
}

private void button1_Click(object sender, EventArgs e)


{
Clipboard.SetText(textBox2.Text);
}

private void button2_Click(object sender, EventArgs e)


{
Clipboard.SetText(textBox2.Text);
textBox2.Clear();

private void button3_Click(object sender, EventArgs e)


{
textBox2.AppendText((Clipboard.GetText()));
}

Step-7
Develop a Windows Form application with a TextBox for phone number input.
Implement an input mask to format the phone number as the user types (e.g., (123) 456-
7890)

Performed by graphically only its has no code.

7: List box in c # Form


private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Monday");
listBox1.Items.Add("Tusday");
listBox1.Items.Add("Wednesday");
listBox1.Items.Add("Thusday");
listBox1.Items.Add("Friday");
listBox1.Items.Add("Saturday");
listBox1.Items.Add("Sunday");
listBox1.SelectionMode = SelectionMode.MultiSimple;
}

private void button1_Click(object sender, EventArgs e)


{

foreach (var item in listBox1.SelectedItems)


{
MessageBox.Show(item.ToString());
}
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs


e)
{

How we Create a button in c#.


How to set the size of the Button in C#?
How to set the Visibility of the Button in C#?
How to set the Background color of the Button in C#?
How to set the Padding of the button in C#?
How to set the Name of the Button in C#?
How to set the Font of the Button in C#?
How to set the Margin of the Buttons in C#?
How to set the Foreground Color of the Button in C#?
How to set the Location of the Button in C#?
Button b1 = new Button();
b1.BackColor = Color.White;
b1.ForeColor = Color.DarkBlue;
b1.Text = "Submit";
b1.Font = new Font("French Script MT",18);
b1.Location = new Point(200,200);
b1.Visible = true;
b1.AutoSize = true;
b1.Name = "First Button";

this.Controls.Add(b1);
How to set Name of the ComboBox in C#?
How to Sort the Elements of the ComboBox in C#?
How to set the Visibility of the ComboBox in C#?
How to Set the Foreground Color of the ComboBox in C#?
How to set the font of the content present in the ComboBox in C#?
How to set the Size of the ComboBox in C#?
How to Add Items in ComboBox in C#?
How to set the Location of the ComboBox in C#?
How to set the Padding of the button in C#?
How to set the Padding of the RadioButton in C#?
How to set the Size of the Label in C#?
How to set the Foreground Color of the Label in C#?
How to set the Background Color of the Label in C#?
How to set the Font of the Content Present in the Label in C#?
How to set Text on the Label in C#?
How to Set the Location of the Label in C#?
How to set the Visibility of the Label in C#?
How to set the Alignment of the Text in the Label in C#?

You might also like