0% found this document useful (0 votes)
54 views5 pages

Aim: Create A Simple Windows Application.: Form1.cs

This document contains code for a simple Windows application with three forms (Form1, Form2, and Program) that demonstrates opening and reading files, changing font and color properties, and adding/removing nodes from a tree view. Form1 contains code for button clicks that open Form2, select colors and fonts, and validate text input. Form2 code handles adding and removing nodes from a tree view. The Program class defines the application entry point.

Uploaded by

Jay Fichadia
Copyright
© Attribution Non-Commercial (BY-NC)
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)
54 views5 pages

Aim: Create A Simple Windows Application.: Form1.cs

This document contains code for a simple Windows application with three forms (Form1, Form2, and Program) that demonstrates opening and reading files, changing font and color properties, and adding/removing nodes from a tree view. Form1 contains code for button clicks that open Form2, select colors and fonts, and validate text input. Form2 code handles adding and removing nodes from a tree view. The Program class defines the application entry point.

Uploaded by

Jay Fichadia
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy