You are on page 1of 5

LAB 15

Aim: Create a simple windows Application.

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Testapplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{

private void fontDialog1_Apply(object sender, EventArgs e)


{

private void b1_Click(object sender, EventArgs e)


{
Form2 f = new Form2();
f.Show();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)


{
Stream myStream;
openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.RestoreDirectory = true;
textBox2.Text = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
textBox1.Text = openFileDialog1.FileName;
StreamReader sr = File.OpenText(openFileDialog1.FileName);
String str;
while ((str = sr.ReadLine()) != null)
{
textBox2.Text += str;

}
textBox2.Text += "----File is Complited---";
sr.Close();
myStream.Close();
}
}
}

private void colorToolStripMenuItem_Click(object sender, EventArgs e)


{
DialogResult dr = colorDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
textBox1.BackColor = colorDialog1.Color;
}
}

private void fontToolStripMenuItem_Click(object sender, EventArgs e)


{
fontDialog1.ShowColor = true;
fontDialog1.Font = textBox1.Font;
fontDialog1.Color = textBox1.ForeColor;
if (fontDialog1.ShowDialog() != DialogResult.Cancel)
{
textBox1.Font = fontDialog1.Font;
textBox1.ForeColor = fontDialog1.Color;
}
}

private void b2_Click(object sender, EventArgs e)


{
DialogResult d = colorDialog1.ShowDialog();
if (d == DialogResult.OK)
{
textBox1.ForeColor = colorDialog1.Color;
}
}

private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)


{

private void b3_Click(object sender, EventArgs e)


{
if (textBox3.Text.Length <= 0)
{
errorProvider1.SetError(textBox3, "enter some value");
}
}

}
}

Form2.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Testapplication
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
TreeNode tr3 = treeView2.SelectedNode;
tr3.Nodes.Add(textBox4.Text);
}

private void button2_Click(object sender, EventArgs e)


{
TreeNode tr3 = treeView2.SelectedNode;
tr3.Nodes.Remove(treeView2.SelectedNode);
}

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)


{
TreeNode tr = treeView1.SelectedNode;
textBox3.Text = tr.FullPath;
}

private void treeView2_AfterSelect(object sender, TreeViewEventArgs e)


{

}
}
}

Program.cs

using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Testapplication
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Output

You might also like