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

Net Practicals Manthan

The document outlines a series of practical exercises for designing, testing, and debugging Windows Forms applications using C#. Each practical focuses on different components and functionalities, such as text boxes, dialog boxes, database connections, and data manipulation, culminating in applications that perform various operations on user inputs and database records.

Uploaded by

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

Net Practicals Manthan

The document outlines a series of practical exercises for designing, testing, and debugging Windows Forms applications using C#. Each practical focuses on different components and functionalities, such as text boxes, dialog boxes, database connections, and data manipulation, culminating in applications that perform various operations on user inputs and database records.

Uploaded by

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

PRACTICAL-1

Aim: Design forms and write , test and debug programs to test its various
properties, methods , events.

-Choose Windows Forms App (.NET Framework) for C# and click Next.
-Name the project - MainForm and Create.(code following) .
-Double click at any point on left side of the code to Debug.

Page-1 2101202030-IT
Output:

Page-2 2101202030-IT
PRACTICAL-2

Aim: Write, test and debug applications to use textbox, label, button.

-Choose Windows Forms App (.NET Framework) for C# and click Next.
-Name the project - MainForm and Create.(code following) .
-Double click at any point on left side of the code to Debug.

Page-3 2101202030-IT
Output: Before writing text

After writing text and clicking button

Page-4 2101202030-IT
PRACTICAL-3

Aim: Write, test and debug application using rich text box, progress bar,
masked text box, link label.
Code:

Page-5 2101202030-IT
Output:
Initial-

Page-6 2101202030-IT
After editing:

LinkLabel: “Visit OpenAi” When clicked, it opens the OpenAI website in the
default browser.

Page-7 2101202030-IT
PRACTICAL-4

Aim: Write, test and debug applications using dialog boxes.

Covered three commonly used dialog boxes:


1. MessageBox: A simple dialog to display messages to the user.
2. OpenFileDialog: Allows users to select a file.
3. ColorDialog: Allows users to select a color.
Code:

Page-8 2101202030-IT
This application will:
 Display a MessageBox when a button is clicked.
 Use an OpenFileDialog to let the user select a file.
 Use a ColorDialog to let the user pick a color, which will then change the
form’s background color.
Output:
Initial-

Page-9 2101202030-IT
Clicked on “show” button-

Clicking on “Open File” button lets you choose file from computer.
Clicked on “select” button -lets you choose color and applies it to form
background.

Page-10 2101202030-IT
PRACTICAL-5

Aim: Write, test and debug applications using math and string
manipulation functions
The application will:
 Accept two numbers and perform basic math operations (addition,
subtraction, multiplication, division).
 Take a text input and allow users to apply various string
manipulations (e.g., converting to uppercase, reversing text, counting
words).
Code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); SetupForm();
}
// Method to set up form components
private void SetupForm()
{
// Set form properties
this.Text = "Math and String Manipulation";
this.Size = new System.Drawing.Size(400, 400);
// Label for number input
Label numberLabel = new Label { Text = "Enter two numbers:",
Location = new System.Drawing.Point(20, 20) };
this.Controls.Add(numberLabel);

Page-11 2101202030-IT
// TextBoxes for numbers
TextBox number1TextBox = new TextBox { Location = new
System.Drawing.Point(20, 50), Width = 100 };
TextBox number2TextBox = new TextBox { Location = new
System.Drawing.Point(130, 50), Width = 100 };
this.Controls.Add(number1TextBox);
this.Controls.Add(number2TextBox);
// Button to calculate
Button calculateButton = new Button { Text = "Calculate",
Location = new System.Drawing.Point(20, 90) };
calculateButton.Click += (sender, e) => {
double num1, num2;
if (double.TryParse(number1TextBox.Text, out num1) &&
double.TryParse(number2TextBox.Text, out num2))
{ PerformMathOperations(num1, num2); }
else { MessageBox.Show("Please enter valid numbers."); } };
this.Controls.Add(calculateButton);
// TextBox for string input
Label stringLabel = new Label { Text = "Enter text:", Location =
new System.Drawing.Point(20, 140) };
TextBox inputTextBox = new TextBox { Location = new
System.Drawing.Point(20, 170), Width = 200 };
this.Controls.Add(stringLabel);
this.Controls.Add(inputTextBox);
// Button to perform string manipulations Button

Page-12 2101202030-IT
stringManipulateButton = new Button { Text = "Manipulate
Text", Location = new System.Drawing.Point(20, 200) };
stringManipulateButton.Click += (sender, e) => {
PerformStringManipulations(inputTextBox.Text);
};
this.Controls.Add(stringManipulateButton);
}
// Method to perform basic math operations
private void PerformMathOperations(double num1, double num2) {
double sum = num1 + num2;
double difference = num1 - num2;
double product = num1 * num2;
double quotient = num2 != 0 ? num1 / num2 : double.NaN;
// Handle division by zero
MessageBox.Show($"Sum: {sum}\nDifference:
{difference}\nProduct: {product}\nQuotient: {(num2 != 0 ?
quotient.ToString() : "undefined")}");
}
// Method to perform string manipulations
private void PerformStringManipulations(string text) {
string upperCase = text.ToUpper();
string lowerCase = text.ToLower();
string reversed = new string(text.Reverse().ToArray());
int wordCount = text.Split(new char[] { ' ', '\t' },
StringSplitOptions.RemoveEmptyEntries).Length;

Page-13 2101202030-IT
MessageBox.Show($"Uppercase: {upperCase}\nLowercase:
{lowerCase}\nReversed: {reversed}\nWord Count: {wordCount}");
}
}
}
The application will:
 Accept two numbers and perform basic math operations (addition,
subtraction, multiplication, division).
 Take a text input and allow users to apply various string
manipulations (e.g., converting to uppercase, reversing text, counting
words).
Output:

Entering numbers and clicked on “Calculate”

Page-14 2101202030-IT
Entering strings and clicked on “Manipulate”

Page-15 2101202030-IT
PRACTICAL-6

Aim: Create and test connection using ado.net to view SQL express
server/Microsoft Access data in textbox etc controls
Creating Database:
 Create a new database –“TestDatabase” in SQL Server
Management Studio.
 Create a sample table -Employees with a few columns

Drag and Drop four textboxes from toolbox at left into the form.

->Name the 1st box –“ textBoxID” ,2nd box- “textBoxFirstName”, 3rd box –
“textBoxLastName” , 4rth box- “textBoxPosition”, and the button –
“btnLoadData”.

->Then create button click event from events in properties.

Code: (add the following namespace –“ System.Data.SqlClient”)

Page-16 2101202030-IT
Output: After clicking the button

Page-17 2101202030-IT
PRACTICAL-7

Aim: Write, test and debug small application to add, edit, search, delete
record in database in bounded mode.
Creating Database:
 Create a new database –“TestDatabase” in SQL Server
Management Studio.
 Create a sample table -Employees with a few columns

-Create a new Windows Forms App (.NET Framework) project


- Drag and Drop DataGridView (named dataGridViewEmployees) and three
TextBoxes for each field (textBoxFirstName, textBoxLastName, and
textBoxPosition).
-Add Buttons for each action: Add, Edit, Delete, and Search.
-Then add the following namespace “System.Data.SqlClient” at the top.
Code:

Page-18 2101202030-IT
Page-19 2101202030-IT
Page-20 2101202030-IT
Output:

Run the application and test each button.


 Add: Enter details in the text boxes and click Add to add a record to
the database.
 Edit: Select a row in the DataGridView, modify text boxes, and click
Edit to update the record.
 Delete: Select a row and click Delete to remove the record.
 Search: Enter a name or part of a name and click Search to filter the
records displayed.

Page-21 2101202030-IT
PRACTICAL-8

Create connection view controls like data-grid view controls

-Create a new Windows Forms App (.NET Framework) project.


-Design the form:
 Drag and drop DataGridView control to the form (named
dataGridViewEmployees).
 Add a Button control to load or refresh the data (named
btnLoadData).

-Code:

Page-22 2101202030-IT
Output: Initial

Clicked on Load Data Button

Page-23 2101202030-IT
PRACTICAL-9

Aim: Write, test and debug small application to add, edit, search, delete
record in database in bounded mode.
Creating Database:
 Create a new database –“TestDatabase” in SQL Server
Management Studio.
 Create a sample table -Employees with a few columns

-Create a new Windows Forms App (.NET Framework) project


- Drag and Drop DataGridView (named dataGridViewEmployees) and three
TextBoxes for each field (textBoxFirstName, textBoxLastName, and
textBoxPosition).
-Add Buttons for each action: Add, Edit, Delete, and Search.
-Then add the following namespace “System.Data.SqlClient” at the top.
Code:

Page-24 2101202030-IT
Page-25 2101202030-IT
Page-26 2101202030-IT
Output:

Run the application and test each button.


 Add: Enter details in the text boxes and click Add to add a record to
the database.
 Edit: Select a row in the DataGridView, modify text boxes, and click
Edit to update the record.
 Delete: Select a row and click Delete to remove the record.
 Search: Enter a name or part of a name and click Search to filter the
records displayed.

Page-27 2101202030-IT
PRACTICAL-10

Aim: Write, test and debug small application to add, edit, search, delete
record in database in unbounded mode i.e. through coding
-Create a new Windows Forms App (.NET Framework) project.
-Design the form: Drag and Drop the following:
 TextBox controls for FirstName, LastName, and Position.
 Button controls: btnAdd, btnEdit, btnDelete, btnSearch, and btnLoad.
 a ListBox to display search results (listBoxResults).

Code:

Page-28 2101202030-IT
Page-29 2101202030-IT
Page-30 2101202030-IT
Output: Clicked on Load Data button

-Enter data in the text fields and click Add to insert a new record.
-Enter an EmployeeID and updated data, then click Edit to update an
existing record.

Page-31 2101202030-IT
-Enter an EmployeeID and click Delete to remove a record.
-Enter a name (or partial name) in FirstName or LastName and click Search
to find matching records.

Page-32 2101202030-IT

You might also like