24
Dot Net Technology Enrollment No: 1 | Page Practical 1 AIM: Create a Window based Application of Arithmetic Calculator in C#.net. Design: Control Name Properties Value TextBox Name textBox1 TextBox Name textBox2 Button Name btnAdd Size 50,50 Font-Size 10 Button Name btnSub Size 50,50 Font-Size 10 Button Name btnMul Size 50,50 Font-Size 10 Button Name btnDiv Size 50,50 Font-Size 10

Practical 1 - · PDF filePractical 1 AIM: Create a Window based Application of Arithmetic Calculator in C#.net. Design: Control Name Properties Value TextBox Name textBox1 TextBox

Embed Size (px)

Citation preview

Dot Net Technology Enrollment No:

1 | P a g e

Practical 1

AIM: Create a Window based Application of Arithmetic Calculator in C#.net.

Design:

Control Name Properties Value

TextBox Name textBox1

TextBox Name textBox2

Button

Name btnAdd

Size 50,50

Font-Size 10

Button

Name btnSub

Size 50,50

Font-Size 10

Button

Name btnMul

Size 50,50

Font-Size 10

Button

Name btnDiv

Size 50,50

Font-Size 10

Dot Net Technology Enrollment No:

2 | P a g e

Form1.cs:

using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnAdd_Click(object sender, EventArgs e) { lblAnswer.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text)); } private void btnSub_Click(object sender, EventArgs e) { lblAnswer.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) - Convert.ToInt32(textBox2.Text)); } private void btnMul_Click(object sender, EventArgs e) { lblAnswer.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text)); } private void btnDiv_Click(object sender, EventArgs e) { lblAnswer.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) / Convert.ToInt32(textBox2.Text)); } } }

Dot Net Technology Enrollment No:

3 | P a g e

Output: Addition

Subtraction

Multiplication

Division

Dot Net Technology Enrollment No:

4 | P a g e

Practical 2

AIM: Create a Window based Application that will use Dialogs controls like OpenFile,

Color, Font, and Print.

Design:

Control Name Properties Value

Label Name label1

Text Dialog Box Controls

Button

Name btnOpenFile

Size 75, 23

Text OpenFile

Font-Bold true

Button

Name btnColor

Size 75, 23

Text Color

Font-Bold true

Button

Name btnFont

Size 75, 23

Text Font

Font-Bold true

Button

Name btnPrint

Size 75, 23

Text Print

Font-Bold true

Dot Net Technology Enrollment No:

5 | P a g e

Form1.cs:

using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnOpenFile_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); if (dlg.ShowDialog() == DialogResult.OK) { String fileName; fileName = dlg.FileName; MessageBox.Show(fileName); } } private void btnColor_Click(object sender, EventArgs e) { ColorDialog dlg = new ColorDialog(); dlg.ShowDialog(); if (dlg.ShowDialog() == DialogResult.OK) { string str = null; str = dlg.Color.Name; MessageBox.Show(str); } } private void btnFont_Click(object sender, EventArgs e) { FontDialog dlg = new FontDialog(); dlg.ShowDialog(); if (dlg.ShowDialog() == DialogResult.OK) { string fontName; float fontSize; fontName = dlg.Font.Name; fontSize = dlg.Font.Size; MessageBox.Show(fontName + " " + fontSize); } }

Dot Net Technology Enrollment No:

6 | P a g e

private void btnPrint_Click(object sender, EventArgs e) { PrintDialog dlg = new PrintDialog(); dlg.ShowDialog(); } } }

Output: OpenFile Dialog

Dot Net Technology Enrollment No:

7 | P a g e

Color Dialog

Dot Net Technology Enrollment No:

8 | P a g e

Font Dialog

Dot Net Technology Enrollment No:

9 | P a g e

Print Dialog

Dot Net Technology Enrollment No:

10 | P a g e

Practical 3

AIM: Create a Window based Application in which create a one window form using Menu

Strip and create a second window form that will inherits the form containing Menu Strip

using visual inheritance.

Design:

Dot Net Technology Enrollment No:

11 | P a g e

Form1.cs:

using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void openToolStripMenuItem1_Click(object sender, EventArgs e) { OpenFileDialog op = new OpenFileDialog(); op.ShowDialog(); if (op.ShowDialog() == DialogResult.OK) { String fileName; fileName = op.FileName; MessageBox.Show(fileName); } } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sd = new SaveFileDialog(); sd.ShowDialog(); } private void closeToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) { } } }

Dot Net Technology Enrollment No:

12 | P a g e

Form2.cs:

using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form2 : Form1 { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } }

Dot Net Technology Enrollment No:

13 | P a g e

Output: Form1

Form2 using Visual Inheritance

Dot Net Technology Enrollment No:

14 | P a g e

Practical 4

AIM: Create a Window based GDI+ Application that will use Graphics class and create

different graphics objects like draw Pen, Font, Brush, Rectangle, Point, Arc, Line and

Ellipse.

Design:

Dot Net Technology Enrollment No:

15 | P a g e

FontForm1.cs:

using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace GDI_Font { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Font fnt = new Font("Verdana", 16); Graphics g = e.Graphics; g.DrawString("GDI+ World", fnt, new SolidBrush(Color.Red), 14, 10); } } }

Output:

Dot Net Technology Enrollment No:

16 | P a g e

Brush and RectangleForm1.cs:

using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace GDI_Plus { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Rectangle rect = new Rectangle(50, 30, 100, 100); LinearGradientBrush lBrush = new LinearGradientBrush(rect, Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal); g.FillRectangle(lBrush, rect); } } }

Output:

Dot Net Technology Enrollment No:

17 | P a g e

Pen and DrawArc Form1.cs:

using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen pn = new Pen(Color.Blue); Rectangle rect = new Rectangle(50, 50, 200, 100); g.DrawArc(pn, rect, 12, 84); } } }

Output:

Dot Net Technology Enrollment No:

18 | P a g e

Point and DrawLine Form1.cs:

using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; namespace GDI_Line { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen pn = new Pen(Color.Blue); // Rectangle rect = new Rectangle(50, 50, 200, 100); Point pt1 = new Point(30, 30); Point pt2 = new Point(110, 100); g.DrawLine(pn, pt1, pt2); } } }

Output:

Dot Net Technology Enrollment No:

19 | P a g e

Pen and DrawEllipse Form1.cs:

using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; namespace GDI_Ellipse { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen pn = new Pen(Color.Blue, 100); Rectangle rect = new Rectangle(50, 50, 200, 100); g.DrawEllipse(pn, rect); } } }

Output:

Dot Net Technology Enrollment No:

20 | P a g e

Practical 5

AIM: Create a Window based application that will insert Registration details like

First Name, Last Name, City, State into database.

Design:

––

Dot Net Technology Enrollment No:

21 | P a g e

Control Name Properties Value

Label Name lblFirstName

Text First Name :

Font-Bold true

Label

Name lblLastName

Text Last Name :

Font-Bold true

Label

Name lblCity

Text City :

Font-Bold true

Label

Name lblState

Text State :

Font-Bold true

TextBox

Name txtFirstName

TabIndex 4

Font-Bold true

TextBox

Name txtLastName

TabIndex 5

Font-Bold true

TextBox

Name txtCity

TabIndex 6

Font-Bold true

TextBox

Name txtlState

TabIndex 7

Font-Bold true

Button

Name btnSave

Size 75, 23

Text Save

Font-Bold true

Dot Net Technology Enrollment No:

22 | P a g e

Dot Net Technology Enrollment No:

23 | P a g e

Form1.cs:

using System; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnSave_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\2016_EVEN_Sem\Dot Net Technology\Dot_Net_Practicals\Window_Based_Practicles\StudentRegistration\WindowsFormsApplication1\Database1.mdf;Integrated Security=True;User Instance=True"); SqlCommand cmd = new SqlCommand("insert UserRegistration values(@FirstName,@LastName,@City,@State)",con); cmd.Parameters.Add("@FirstName",txtFirstName.Text); cmd.Parameters.Add("@LastName",txtLastName.Text); cmd.Parameters.Add("@City",txtCity.Text); cmd.Parameters.Add("@State",txtState.Text); con.Open(); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("User Registration Detail Saved Successfully"); } } } }

Dot Net Technology Enrollment No:

24 | P a g e

Output: Insert Data