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

Oop Prac2

The document contains two C# Windows Forms applications, both implementing a form with buttons for various functionalities. The first application allows creating a text file, writing to it, and reading from it to display in a list box. The second application enables opening a file to read its content, printing a message when printing is initiated, and changing the font of a text box using a font dialog.
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)
11 views5 pages

Oop Prac2

The document contains two C# Windows Forms applications, both implementing a form with buttons for various functionalities. The first application allows creating a text file, writing to it, and reading from it to display in a list box. The second application enables opening a file to read its content, printing a message when printing is initiated, and changing the font of a text box using a font dialog.
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/ 5

QUESTION 1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

namespace WindowsFormsApplication4

public partial class Form1 : Form

private string f = "subject.txt";

public Form1()

InitializeComponent();

private void button1_Click(object sender, EventArgs e)

if(!File.Exists(f)){

File.Create(f).Close();

}
}

private void button2_Click(object sender, EventArgs e)

using (StreamWriter write = new StreamWriter(f,true)){

write.WriteLine(textBox1.Text);

private void button3_Click(object sender, EventArgs e)

using (StreamReader read = new StreamReader(f))

string line;

while ((line = read.ReadLine()) != null) {

listBox1.Items.Add(line);

}
QUESTION 2
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void button1_Click(object sender, EventArgs e)


{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = File.ReadAllText(openFileDialog.FileName);
}
}

private void button2_Click(object sender, EventArgs e)


{

PrintDialog printDialog = new PrintDialog();


if (printDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("Printing...");
}
}

private void button3_Click(object sender, EventArgs


{
FontDialog fontDialog = new FontDialog();
if (fontDialog.ShowDialog() == DialogResult.OK)
{
textBox1.Font = fontDialog.Font;
}
}
}
}

You might also like