0% found this document useful (0 votes)
20 views7 pages

Font Dialog

The document outlines the steps to write a program to perform common dialog classes in C#.NET. It involves starting a Windows Forms application project in Visual Studio 2010, adding controls like RichTextBox and buttons, importing namespaces, and creating objects for dialog classes to perform operations like opening, saving, setting font and color. The coding section implements methods for the open, save, font and color dialog classes that are triggered by menu button clicks and update the RichTextBox control.

Uploaded by

Amutha Arun
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)
20 views7 pages

Font Dialog

The document outlines the steps to write a program to perform common dialog classes in C#.NET. It involves starting a Windows Forms application project in Visual Studio 2010, adding controls like RichTextBox and buttons, importing namespaces, and creating objects for dialog classes to perform operations like opening, saving, setting font and color. The coding section implements methods for the open, save, font and color dialog classes that are triggered by menu button clicks and update the RichTextBox control.

Uploaded by

Amutha Arun
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/ 7

12 .

COMMON DIALOG CLASSES

August 7, 2014

Aim:
~~~~

To write a program to perform the common dialog class using c#.net


Procedure:
~~~~~~~~~

Step1: Start the program in the Microsoft Visual Studio 2010.


Step2: File->new->project Select the project type as visual c# and select
the installed template as windows Forms application.
Step3: Choose a Name, Location and Solution name.
Step4: Using menu script from toolbox, Ritchtextbox and Buttons are used in design
window.
Step5: Using namespaces to corresponding controls.
Step6: Create objects for particular classes and performing save,open,font and color
operations.
Step7: End of the program.

12PA01

Page 47

12 .COMMON DIALOG CLASSES

August 7, 2014

CODING:
~~~~~~~
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog objOFD = new OpenFileDialog();
objOFD.Filter = "ALL File|*.*|Text Files|*.txt";
objOFD.FilterIndex = 1;
if (objOFD.ShowDialog() == DialogResult.OK)
{
string flname;
flname = objOFD.FileName;
FileStream objFS = new FileStream(flname, FileMode.OpenOrCreate,
FileAccess.ReadWrite);
StreamReader objSR = new StreamReader(objFS);
objSR.BaseStream.Seek(0, SeekOrigin.Begin);
data.Text = objSR.ReadLine();
while (objSR.Peek() > -1)
12PA01

Page 48

12 .COMMON DIALOG CLASSES

August 7, 2014

{
data.Text = data.Text + "\r\n" + objSR.ReadLine();
}
objSR.Close();
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog objSFD;
objSFD = new SaveFileDialog();
objSFD.Filter = "All File|*.*|Text files|*.txt";
objSFD.FilterIndex = 1;
if (objSFD.ShowDialog() == DialogResult.OK)
{
data.SaveFile(objSFD.FileName, RichTextBoxStreamType.PlainText);
MessageBox.Show("File Saved");
}
}
private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
FontDialog objFD = new FontDialog();
if (objFD.ShowDialog() == DialogResult.OK)
{
data.Font = objFD.Font;
}
}
private void colorToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog objCD = new ColorDialog();
if (objCD.ShowDialog() == DialogResult.OK)
{
data.ForeColor = objCD.Color;
}
}
12PA01

Page 49

12 .COMMON DIALOG CLASSES

August 7, 2014

private void clearToolStripMenuItem_Click(object sender, EventArgs e)


{
data.Text = "";
}
}
}

12PA01

Page 50

12 .COMMON DIALOG CLASSES

August 7, 2014

Output:
~~~~~~

12PA01

Page 51

12 .COMMON DIALOG CLASSES

August 7, 2014

Result:
~~~~~
12PA01

Page 52

12 .COMMON DIALOG CLASSES

August 7, 2014

Thus the common dialog class was successfully performed.

12PA01

Page 53

You might also like