VISUAL PROGRAMING LAB
DOCUMENTATION ON
Simple text editor using C#.net
SUBMITTED IN PARTIAL FULFILLMENT OF
THE REQUIREMENTS TO AWARD
THE DEGREE OF BACHELOR OFM
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING
DESIGNED AND DEVELOPED BY
R. Ravikumar(22241A66B5)
P. Harshavardhan Reddy(22241A66B1)
V. Nikhil (22241A66C5)
UNDER THE GUIDNCE OF:
Mr. M. Anjaneyulu, Mr. N Devendar
Asst. professor
DEPARTMENT OF
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING
GOKARAJU RANGARAJU INSTITUTE OF ENGINEERING AND
TECHNOLOGY
(Bachupally, Hyderabad,500090
Faculty Sign: Hod Sign:
1
VISUAL PROGRAMING LAB
INDEX
S.No Table of Contents Page Number
1 Introduction 4
● Problem Statement
● Goal of the Project
2 Text Editor UI 5
● Description
● Why C# and .NET?
3 Set up Environment & Design Windows 5
Forms Structure
● Visual Studio Installation
● Windows Forms Project Setup
● Description of the Setup
4 Creating the User Interface 6
● Designing the Main Form
● Adding MenuStrip and ToolStrip
● Adding TextBox (RichTextBox)
● Description of the Code
5 Implementing Basic File Operations 7
New File, Open File, Save File, Save As
Code Implementation
Description of the Code
6 Implementing Edit Operations 8
2
VISUAL PROGRAMING LAB
Cut, Copy, Paste, Undo, Redo
7 Formatting Text 9
Changing Font and Font Size
Changing Text Color
8 Adding Additional Features 10
● Find and Replace
● Word Wrap
● Status Bar
9 Code Implementations 11
10 Result 18
11 Testing the Text Editor 20
Testing the Functionality
Description of Testing Process
12 Limitations 21
Limited Dynamic Functionality
Security Concerns
13 Conclusion
Summary of the Project
3
VISUAL PROGRAMING LAB
1.Introduction
In today's digital age, text editors are indispensable tools for software development,
document creation, and various other tasks. They allow users to create, edit, and
manage text files efficiently, providing essential functionalities like text
formatting, file handling, and search operations.
Problem Statement
While numerous advanced text editors are available, many are either too complex
for basic users or too limited for advanced users. Additionally, these editors often
come with features that may not be necessary for all, resulting in a cluttered and
overwhelming interface.
Goal of the Project
The goal of this project is to develop a simple, user-friendly text editor using C#
and the .NET framework. This text editor will offer essential features such as
creating, opening, saving, and editing text files, along with basic formatting
options. By focusing on core functionalities and an intuitive interface, the editor
aims to cater to both novice and experienced users who need a straightforward tool
for managing text documents.
This document will guide you through setting up the development environment,
designing the user interface, implementing core functionalities, and testing the
application. By the end of this project, you will have a functional text editor that
can be further enhanced with additional features as needed.
4
VISUAL PROGRAMING LAB
2.Text Editor UI
Description
The text editor is designed to provide a clean, straightforward interface for
creating, editing, and managing text documents. Key components include a menu
strip for commands, a toolbar for quick access to functions, and a rich text box for
content. The layout is intuitive, minimizing the learning curve for new users while
offering essential text editing features.
Why C# and .NET?
C# and the .NET framework are ideal for building this text editor due to their
robust libraries, ease of use, and strong support for Windows Forms applications.
These technologies enable rapid development and offer built-in functionality for
file handling, text manipulation, and UI design. They ensure excellent performance
and stability, making the text editor reliable and efficient.
Using C# and .NET also benefits from extensive resources and community
support, facilitating problem-solving and future feature implementation. This
choice ensures efficient development and effective long-term maintenance of the
text editor.
3.Set up Environment & Design Windows Forms Structure
Visual Studio Installation
1. Download and install Visual Studio.
2. During installation, select the "Desktop development with C#.net" workload.
3. After installation, launch Visual Studio and sign in if required.
Windows Forms Project Setup
1. Open Visual Studio and create a new project.
2. Select "Windows Forms App (.NET Framework)".
3. Name your project (e.g., "SimpleTextEditor") and choose a location to save
it.
4. Click "Create" to set up the project.
5
VISUAL PROGRAMING LAB
Designing the Main Form
1. In the Solution Explorer, open Form1.cs.
2. Use the toolbox to drag and drop controls onto the form.
o MenuStrip: Add a MenuStrip to the form and create the following
menu items:
File: New, Open, Save, Save As, Exit
Edit: Cut, Copy, Paste, Undo, Redo
Format: Font, Color
Help: About
o ToolStrip: Add a ToolStrip for quick access to common actions like
New, Open, Save, Cut, Copy, and Paste.
o RichTextBox: Add a RichTextBox to serve as the main text area.
3. Arrange the controls to ensure a clean and user-friendly interface.
Description of the Setup
This setup involves installing Visual Studio, creating a new Windows Forms
project, and designing the main form with essential UI components. The
MenuStrip provides easy access to commands, the ToolStrip offers quick action
buttons, and the RichTextBox serves as the primary text input area. This layout
ensures an intuitive and efficient user experience.
4.Creating the User Interface
Designing the Main Form
1. MenuStrip
o Add a MenuStrip: From the Toolbox, drag a MenuStrip onto the
form.
o Create Menu Items: Add the following top-level menu items: File,
Edit, Format, Help.
File Menu: Add sub-items: New, Open, Save, Save As, Exit.
Edit Menu: Add sub-items: Cut, Copy, Paste, Undo, Redo.
Format Menu: Add sub-items: Font, Color.
Help Menu: Add sub-item: About.
2. ToolStrip
6
VISUAL PROGRAMING LAB
o Add a ToolStrip: Drag a ToolStrip from the Toolbox onto the form
below the MenuStrip.
o Add Buttons: Add buttons for New, Open, Save, Cut, Copy, and
Paste.
o Set Images: Assign relevant images/icons to these buttons for better
user recognition.
3. RichTextBox
o Add a RichTextBox: Drag a RichTextBox from the Toolbox to fill
the remaining space on the form. This will be the main area for text
editing.
4. StatusStrip (Optional)
o Add a StatusStrip: Drag a StatusStrip onto the form.
o Add Status Labels: Use status labels to display information like
cursor position or file status.
5.Implementing Basic File Operations
To provide essential file operations such as creating, opening, saving, and saving
files with a new name, follow these steps:
New File
Functionality: Clears the current text in the RichTextBox and resets the
editor to a new, untitled document state.
Steps:
1. Check if the current document has unsaved changes.
2. Prompt the user to save the changes if any.
3. Clear the RichTextBox and reset any associated variables.
Open File
Functionality: Allows the user to open and edit an existing text file.
Steps:
1. Use an OpenFileDialog to let the user select a file.
2. Load the selected file’s content into the RichTextBox.
7
VISUAL PROGRAMING LAB
3. Update the editor’s state to reflect the opened file.
Save File
Functionality: Saves the current content of the RichTextBox to the existing
file.
Steps:
1. Check if the document has an associated file path.
2. If yes, save the content to the file.
3. If no, invoke the Save As functionality.
Save As
Functionality: Saves the current content to a new file specified by the user.
Steps:
1. Use a SaveFileDialog to let the user specify the file name and
location.
2. Save the content of the RichTextBox to the specified file.
3. Update the editor’s state to reflect the new file path.
Exit
Functionality: Closes the application.
Steps:
1. Check if the current document has unsaved changes.
2. Prompt the user to save the changes if any.
3. Close the application.
6.Implementing Edit Operations
To provide essential text editing features such as cutting, copying, pasting,
undoing, and redoing actions, follow these steps:
Cut
Functionality: Removes the selected text from the RichTextBox and places
it on the clipboard.
8
VISUAL PROGRAMING LAB
Steps:
1. Check if there is any selected text.
2. Cut the selected text and place it on the clipboard.
Copy
Functionality: Copies the selected text from the RichTextBox to the
clipboard without removing it.
Steps:
1. Check if there is any selected text.
2. Copy the selected text to the clipboard.
Paste
Functionality: Inserts the content from the clipboard into the RichTextBox
at the current cursor position.
Steps:
1. Check if there is any text on the clipboard.
2. Paste the clipboard content into the RichTextBox.
Undo
Functionality: Reverts the last action performed in the RichTextBox.
Steps:
1. Check if there are actions to undo.
2. Perform the undo operation.
Redo
Functionality: Re-applies the last action that was undone in the
RichTextBox.
Steps:
1. Check if there are actions to redo.
2. Perform the redo operation.
9
VISUAL PROGRAMING LAB
7.Formatting Text
To enhance the text editor's functionality, it's important to include options for text
formatting such as changing the font, font size, and text color. Follow these steps
to implement these features:
Changing Font and Font Size
Functionality: Allows users to select and apply different fonts and font sizes
to the text in the RichTextBox.
Steps:
1. Provide a Font dialog box for users to select a font and size.
2. Apply the selected font and size to the selected text or to the text that
will be typed next.
Changing Text Color
Functionality: Allows users to change the color of the text in the
RichTextBox.
Steps:
1. Provide a Color dialog box for users to select a text color.
2. Apply the selected color to the selected text or to the text that will be
typed next.
8.Adding Additional Features
To make the text editor more functional and user-friendly, consider adding
additional features such as find and replace, word wrap, and a status bar. Follow
these steps to implement these features:
Find and Replace
Functionality: Enables users to search for specific text within the document
and replace it with new text.
Steps:
1. Create a dialog box for finding and replacing text.
2. Allow users to input the text to find and the text to replace it with.
3. Implement search functionality to locate the specified text.
10
VISUAL PROGRAMING LAB
4. Replace the found text with the new text as specified by the user.
Word Wrap
Functionality: Allows users to toggle word wrap in the RichTextBox,
ensuring long lines of text are wrapped within the visible area.
Steps:
1. Provide an option (e.g., a menu item) to toggle word wrap.
2. Enable or disable word wrap in the RichTextBox based on the user's
selection.
Status Bar
Functionality: Displays information about the document and the current
state of the text editor, such as cursor position and file status.
Steps:
1. Add a StatusStrip control to the form.
2. Include status labels to show information like line number, column
number, and file status (e.g., modified or saved).
3. Update the status labels dynamically as the user interacts with the text
editor.
9.Code Implementation:
MainWindow.xaml:
<Window x:Class="Super_simple_text_editor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation
"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-
compatibility/2006"
xmlns:local="clr-namespace:Super_simple_text_editor"
mc:Ignorable="d"
11
VISUAL PROGRAMING LAB
Title="Simple Text Editor" Height="700" Width="1150">
<Grid>
<Button Name="openFileBtn" Click="openFileBtn_Click"
Content="Open a Text File" HorizontalAlignment="Left"
Margin="69,93,0,0" VerticalAlignment="Top" Width="117"
Height="38"/>
<Button Name="saveFileBtn" Click="saveFileBtn_Click"
Content="Save a Text File" HorizontalAlignment="Left"
Margin="69,156,0,0" VerticalAlignment="Top" Width="117"
Height="38"/>
<TextBox Name="fileSpaceBox" BorderBrush="Black"
BorderThickness="1" VerticalScrollBarVisibility="Auto"
FontSize="14" KeyDown="fileSpaceBox_KeyDown"
HorizontalAlignment="Left" Height="550" Margin="225,93,0,0"
TextWrapping="Wrap" Text="" VerticalAlignment="Top"
Width="890"/>
<TextBlock Name="fileNameBlock" Background="LightGray"
FontSize="14" ScrollViewer.HorizontalScrollBarVisibility="Auto"
HorizontalAlignment="Left" Margin="225,49,0,0"
TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="890"
Height="25"/>
<TextBlock HorizontalAlignment="Left"
Margin="614,28,0,0" TextWrapping="Wrap" Text="File Name:"
VerticalAlignment="Top"/>
</Grid>
</Window>
MainWindow.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
12
VISUAL PROGRAMING LAB
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.IO;
namespace Super_simple_text_editor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public string fileDialogName = "";
public string[] readText = new string[1000];
public MainWindow()
{
InitializeComponent();
}
private void openFileBtn_Click(object sender,
RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog();
fileDialog.InitialDirectory = @"C:\SampleTxtDocs";
fileDialog.DefaultExt = "txt";
fileDialog.Filter = "(*.txt)|";
fileDialog.Multiselect = false;
fileDialog.ShowDialog();
fileDialogName = fileDialog.FileName;
if (fileDialogName != "")
{
fileNameBlock.Text = "";
fileSpaceBox.Text = "";
fileNameBlock.Text = fileDialogName;
readText = File.ReadAllLines(fileDialogName);
for (int i = 0; i < readText.Length; i++)
{
13
VISUAL PROGRAMING LAB
fileSpaceBox.Text += readText[i] + '\n';
}
}
}
private void saveFileBtn_Click(object sender,
RoutedEventArgs e)
{
if (fileDialogName != "")
{
File.WriteAllText(fileDialogName,
fileSpaceBox.Text);
}
}
private void fileSpaceBox_KeyDown(object sender,
System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
var caretIndex = fileSpaceBox.CaretIndex;
fileSpaceBox.Text =
fileSpaceBox.Text.Insert(caretIndex, "\n");
fileSpaceBox.CaretIndex = caretIndex + 1;
}
}
}
}
SimpleTextEditor.csproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$
(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$
(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
14
VISUAL PROGRAMING LAB
<Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>
<Platform Condition=" '$(Platform)' == ''
">AnyCPU</Platform>
<ProjectGuid>{3ABE302A-BFBD-4746-BF87-
29E9025E9DD5}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Super_simple_text_editor</RootNamespace>
<AssemblyName>Super simple text editor</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects
>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
15
VISUAL PROGRAMING LAB
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
16
VISUAL PROGRAMING LAB
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
</Project>
App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
17
VISUAL PROGRAMING LAB
App.xaml
<Application x:Class="Super_simple_text_editor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation
"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-
namespace:Super_simple_text_editor"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
10. Result:
18
VISUAL PROGRAMING LAB
19
VISUAL PROGRAMING LAB
20
VISUAL PROGRAMING LAB
11.Testing the Text Editor
Testing is crucial to ensure the functionality, usability, and reliability of the text
editor. Here’s how you can approach testing:
Unit Testing
Functional Testing: Verify that each feature works as expected. Test
opening, saving, and editing files, as well as text formatting and editing
operations (cut, copy, paste, undo, redo).
Boundary Testing: Test edge cases such as very large files, empty files,
files with special characters, and files with different encodings.
UI Testing: Ensure that all UI components (menu items, toolbars, text area)
respond correctly to user interactions.
Error Handling Testing: Test how the text editor handles unexpected
inputs or errors, such as attempting to open a non-existent file or saving to a
read-only location.
User Testing
Usability Testing: Have users (both novices and experienced) interact with
the text editor to evaluate its ease of use, intuitiveness, and learnability.
Feedback Collection: Gather feedback on features, interface design, and
overall user experience to identify areas for improvement.
Performance Testing: Evaluate the text editor’s performance in terms of
speed when opening, saving, and editing large files.
Automation Testing (Optional)
Automated UI Testing: Use tools like Selenium or Microsoft UI
Automation to automate UI tests that simulate user interactions and verify
expected behaviors.
Regression Testing: Automate tests to ensure that new changes or bug fixes
do not introduce unintended issues.
Documentation
Test Documentation: Document test cases, results, and any identified bugs
or issues. Maintain a record of improvements made based on testing
feedback.
21
VISUAL PROGRAMING LAB
Testing ensures that the text editor meets functional requirements, performs
reliably, and provides a satisfactory user experience. Continuous testing and
feedback are essential for refining and enhancing the editor’s capabilities over
time.
12. Limitations
To ensure transparency about the text editor's capabilities and potential
shortcomings, consider the following limitations:
Limited Dynamic Functionality: While the text editor provides essential
features for text editing, it may lack advanced functionalities found in more
specialized editors. Features like syntax highlighting, advanced search
options, or integration with version control systems are not included.
Security Concerns: The text editor does not incorporate advanced security
features such as encryption for saved files or protection against malicious
script execution. Users should exercise caution when opening files from
untrusted sources.
13. Conclusion
In summary, the development of this simple text editor using C# and .NET aimed
to provide a straightforward yet effective tool for creating and editing text
documents. By focusing on essential functionalities such as file operations, text
formatting, and basic editing capabilities, the editor offers a user-friendly interface
suitable for both novice and experienced users.
Moving forward, enhancements could include integrating more advanced features
like syntax highlighting, improving file management options, and enhancing user
interface responsiveness. Overall, this project demonstrates the foundational
aspects of building a text editor in C# while leaving room for future development
and customization based on user feedback and evolving requirements.
22