Switch to full style
Codes, tips and tricks,discussions and solutions related to C#
Post a reply

NotePad C# code

Fri May 09, 2008 2:21 pm

Contains Notepad project C# code implementation , you can download it Freely , enjoy.
code samples :
cpp code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace Notepad
{
public partial class Form1 : Form
{
int current = 0;
static string text;
static int check = 0;
static int firstTime = 0;
static string destination = "";
string cutData, copyData, pasteData,deleteData,undoData;
public Form1()
{
InitializeComponent();
}

public void save()
{
SaveFileDialog save = new SaveFileDialog();
save.InitialDirectory = "D:";
save.ShowHelp = true;
save.RestoreDirectory = true;
save.Title = "Save Notepad file";
save.Filter = "Text Document (*.txt)|*.txt";
if (save.ShowDialog() == DialogResult.OK)
{
using (StreamWriter write = new StreamWriter(save.FileName, true))
{
write.Write(textBox1.Text);
}
}
destination = save.FileName;
changeName(destination);
}
public void changeName(string path)
{
char[] fileName;
fileName = path.ToCharArray();
path = "";
for (int i = fileName.Length - 1; i >= 0; i--)
{
if (fileName[i] == '\\')
{
for (int j = i + 1; j < fileName.Length; j++)
{
path += fileName[j];
}
break;
}
}
this.Text = path;
}

public void exit()
{
if (current == 1)
{
wantToSave();
}
DialogResult exit;
exit = MessageBox.Show("Are u sure u want to exit", "Exit", MessageBoxButtons.YesNo);
if (DialogResult.Yes == exit)
{
MessageBox.Show("Thanks for using my Notepad", "Gooooooooooood bye");
Application.ExitThread();
}
}

public void wantToSave()
{
DialogResult saveVar;
saveVar = MessageBox.Show("Do u want to save ur changes", "Save", MessageBoxButtons.YesNoCancel);
if (DialogResult.Yes == saveVar)
{
save();
textBox1.Text = "";
this.Text = "Untitled - Notepad";
current = 0;
}
if (DialogResult.No == saveVar)
{
textBox1.Text = "";
this.Text = "Untitled - Notepad";
current = 0;
}
}

public void select()
{
Point po = new Point();
if (statusBarToolStripMenuItem.Checked == true)
{
po.X = 0;
po.Y = 240;
statusStrip1.Visible = true;
hScrollBar1.Location = po;
hScrollBar1.Visible = true;
}
else
{
po.X = 0;
po.Y = 262;
statusStrip1.Visible = false;
hScrollBar1.Location = po;
hScrollBar1.Visible = true;
}
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
// OPEN
wantToSave();
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory="D:";
open.Multiselect = true;
open.RestoreDirectory = true;
open.Title = "Open Notepad file";
open.Filter = "Text Document (*.txt)|*.txt";
if (open.ShowDialog() == DialogResult.OK)
{
string path = open.FileName;
changeName(path);
}
using(StreamReader read=new StreamReader (open.FileName,false))
{
textBox1.Text = read.ReadToEnd();
}
timer1.Enabled = true;
}

private void timer1_Tick(object sender, EventArgs e)
{
}

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
// NEW
if (current == 1)
{
wantToSave();
}
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
// EXIT
exit();
}

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
// SAVE AS
save();
}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
// SAVE
if (firstTime == 0)
{
save();
}
else
{
using (StreamWriter write = new StreamWriter(destination, true))
{
write.Write(textBox1.Text);
}
}
firstTime++;
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
exit();
e.Cancel = true;
}

private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
if (DialogResult.OK == fontDialog1.ShowDialog())
{
textBox1.Font = fontDialog1.Font;
textBox1.ForeColor = fontDialog1.Color;
}
}

private void wordWarpToolStripMenuItem_Click(object sender, EventArgs e)
{
Point po = new Point();
if (wordWarpToolStripMenuItem.Checked == true)
{
statusBarToolStripMenuItem.Enabled = false;
statusStrip1.Visible = false;
hScrollBar1.Visible = false;
po.X = 0;
po.Y = 240;
hScrollBar1.Location =po;
}
else
{
statusBarToolStripMenuItem.Enabled = true;
select();
}
}

private void statusBarToolStripMenuItem_Click(object sender, EventArgs e)
{
select();
}

private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.SelectAll();
}

private void timeDateToolStripMenuItem_Click(object sender, EventArgs e)
{
string value = textBox1.Text;
textBox1.Text = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +

DateTime.Now.Second.ToString() + " " + DateTime.Now.Date.ToString() + value;
}

private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
findToolStripMenuItem.Enabled = true;
findNextToolStripMenuItem.Enabled = true;
if (textBox1.SelectedText != "")
{
copyToolStripMenuItem.Enabled = true;
pasteToolStripMenuItem.Enabled = true;
cutToolStripMenuItem.Enabled = true;
deleteToolStripMenuItem.Enabled = true;
}
else
{
copyToolStripMenuItem.Enabled = false;
deleteToolStripMenuItem.Enabled = false;
cutToolStripMenuItem.Enabled =false;
}
if (check != 0)
{
undoToolStripMenuItem.Enabled = true;
}
else
{
undoToolStripMenuItem.Enabled = false;
}
}
}

private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText != "")
{
cutData = textBox1.SelectedText;
textBox1.Text = textBox1.Text.Remove(textBox1.SelectionStart);
check = -1;
text = textBox1.Text;
}
}

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText != "")
{
copyData = textBox1.SelectedText;
check = 1;
}
}

private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (check == -1)
{
pasteData = cutData;
textBox1.Text += pasteData;
}
if (check == 1)
{
pasteData = copyData;
textBox1.Text += pasteData;
}
}

private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText != "")
{
deleteData = textBox1.SelectedText;
textBox1.Text = textBox1.Text.Remove(textBox1.SelectionStart);
check = 2;
text = textBox1.Text;
}
}

private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
if (check == 2)
{
undoData = deleteData;
textBox1.Text = text + undoData;
deleteData = "";
}
if (check == -1)
{
undoData = cutData;
textBox1.Text = text + undoData;
cutData = "";
}
}

private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
StoreData.setAllText(textBox1.Text);
Find find = new Find();
find.Show();
}

private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
{
StoreData.setAllText(textBox1.Text);
Replace_All replace = new Replace_All();
replace.Show();
}

private void goToToolStripMenuItem_Click(object sender, EventArgs e)
{
StoreData.setAllText(textBox1.Text);
Go_To goTo = new Go_To();
goTo.Show();
}

private void findNextToolStripMenuItem_Click(object sender, EventArgs e)
{
StoreData.setAllText(textBox1.Text);
Find find = new Find();
find.Show();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
current = 1;
}

private void helpTopicsToolStripMenuItem_Click(object sender, EventArgs e)
{
}

}
}


Find form:
cpp code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Notepad
{
public partial class Find : Form
{
int k = 0;
string text;
static int curr = 0;
public Find()
{
InitializeComponent();
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
// string[] k;
// k[0] = Form1.textBox1.Lines.GetValue(0);
if (Form1.textBox1.Text == "")
{
MessageBox.Show("Can not find " + textBox1.Text, "Notepad");
}
else
{
text = StoreData.getAllText();
if (radioButton2.Checked == true)
{
for (int i = curr; i <= text.Length; i++)
{
if (curr + textBox1.Text.Length <= text.Length)
{
if (text.Substring(curr, textBox1.Text.Length) == textBox1.Text)
{
Form1.textBox1.Select(curr, textBox1.Text.Length);
curr++;
break;
}
else
{
curr++;
if (curr == text.Length)
{
MessageBox.Show("Can not find " + textBox1.Text, "Notepad");
}
}
}
}
}
else
{
// k to able the current continuted not in the start
if (k == 0)
{
k = 1;
curr = text.Length - textBox1.Text.Length;
StoreData.setCurrent(curr);
}
for (int i = StoreData.getCurrent(); i >= 0; i--)
{
// if (curr <= 0)
//{
if (text.Substring(curr, textBox1.Text.Length) == textBox1.Text)
{
Form1.textBox1.Select(curr, textBox1.Text.Length);

curr--;
StoreData.setCurrent(curr);
break;

}
else
{
curr--;
if (curr == 0)
{
MessageBox.Show("Can not find " + textBox1.Text, "Notepad");
}
}
// }
StoreData.setCurrent(curr);
}
}
text = Form1.textBox1.Text;
StoreData.setAllText(Form1.textBox1.Text);
Form1.textBox1.Focus();
}
}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
curr = 0;
k = 0;
button1.Enabled = true;
}
}
}
}



Attachments
Notepad.rar
(81.7 KiB) Downloaded 12628 times

Re: NotePad C# code

Fri Mar 27, 2009 12:28 am

thx a lot man :)

Re: NotePad C# code

Tue Aug 03, 2010 10:54 am

thanks

Re: NotePad C# code

Wed Sep 22, 2010 7:58 am

Thanks a lot for the post.
I got essential files for C#. I will try to use them....

Really very thanks for Notepad.rar :)

Post a reply
  Related Posts  to : NotePad C# code
 make notepad editor in c     -  
 Freeman chain code algorithm code     -  
 i want code for connecting mobile and pc can u send me code     -  
 asking for code     -  
 code     -  
 XML Paging Code     -  
 Code of stack     -  
 I need help with a html code     -  
 US Zip Code Validation     -  
 polyalphabetic J# Code     -  

Topic Tags

C# Projects