Click here to Skip to main content
12,502,578 members (54,828 online)
Click here to Skip to main content

Stats

87.5K views
5K downloads
108 bookmarked
Posted

Encrypting Editor Notepad Replacement

, 28 Jul 2014 CPOL
A C# .NET 3.5 (Win7) Windows Forms Application with source code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CryptPad
{
	public partial class Find : Form
	{
		CryptPad Crypt_Pad;

		public Find ()
		{
			InitializeComponent ();
			this.Font = SystemFonts.MessageBoxFont;
		}

		private void Find_Load (object sender, EventArgs e)
		{
			Crypt_Pad = (CryptPad) this.Owner;
			this.textFind.Text = Crypt_Pad.find_string;
			comboBoxPatterns.Tag = textFind;
			this.checkBoxRegEx.Checked = null != Crypt_Pad.find_regex;
			this.comboBoxPatterns.SelectedIndexChanged += new System.EventHandler (Crypt_Pad.comboBoxPatterns_SelectedIndexChanged);
			this.comboBoxPatterns.Click += new System.EventHandler (Crypt_Pad.comboBoxPatterns_Click);
			UpdateFindNextButton ();
			Crypt_Pad.Position (this);
		}

		private void Find_FormClosed (object sender, FormClosedEventArgs e)
		{
			Crypt_Pad.find_Form = null;
		}

		private void textFind_Enter (object sender, EventArgs e)
		{
			comboBoxPatterns.Items.Clear ();
			comboBoxPatterns.Items.AddRange (Crypt_Pad.combo_search);
			comboBoxPatterns.Items.AddRange (Crypt_Pad.combo_base);
			if (checkBoxRegEx.Checked)
				comboBoxPatterns.Items.AddRange (Crypt_Pad.combo_regex_find);
			comboBoxPatterns.Text = (string) comboBoxPatterns.Items[0];
		}

		private void textFind_TextChanged (object sender, EventArgs e)
		{
			UpdateFindNextButton ();
		}

		private void checkBoxRegEx_CheckedChanged (object sender, EventArgs e)
		{
			((TextBox) comboBoxPatterns.Tag).Focus ();
		}

		private void UpdateFindNextButton ()
		{
			buttonFind.Enabled = textFind.Text.Length > 0;
			buttonFindPrevious.Enabled = textFind.Text.Length > 0;
		}

		private void buttonFindPrevious_Click (object sender, EventArgs e)
		{
			Crypt_Pad.checkBoxMatchCase = this.checkBoxMatchCase.Checked;
			if (Crypt_Pad.checkBoxRegEx (this.checkBoxRegEx.Checked, this.textFind.Text))
				return;
			Crypt_Pad.FindNext (false);
			Crypt_Pad.Position (this);
		}

		private void buttonFind_Click (object sender, EventArgs e)
		{
			Crypt_Pad.checkBoxMatchCase = this.checkBoxMatchCase.Checked;
			if (Crypt_Pad.checkBoxRegEx (this.checkBoxRegEx.Checked, this.textFind.Text))
				return;
			Crypt_Pad.FindNext (true);
			Crypt_Pad.Position (this);
		}

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

		private void contextMenuStrip_Opening (object sender, CancelEventArgs e)
		{
			toolStripMenuUndo.Enabled = textFind.CanUndo;
			toolStripMenuPaste.Enabled = Clipboard.ContainsText ();
			if (0 < textFind.SelectionLength)
			{
				toolStripMenuCut.Enabled = true;
				toolStripMenuCopy.Enabled = true;
				toolStripMenuDelete.Enabled = true;
			}
			else
			{
				toolStripMenuCut.Enabled = false;
				toolStripMenuCopy.Enabled = false;
				toolStripMenuDelete.Enabled = false;
			}
		}

		private void toolStripMenuUndo_Click (object sender, EventArgs e)
		{
			textFind.Undo ();
		}

		private void toolStripMenuCut_Click (object sender, EventArgs e)
		{
			string s = textFind.SelectedText;
			if (!checkBoxRegEx.Checked)
				s = Crypt_Pad.Unescape (s);
			Clipboard.SetText (s);
			textFind.Paste ("");
		}

		private void toolStripMenuCopy_Click (object sender, EventArgs e)
		{
			string s = textFind.SelectedText;
			if (!checkBoxRegEx.Checked)
				s = Crypt_Pad.Unescape (s);
			Clipboard.SetText (s);
		}

		private void toolStripMenuPaste_Click (object sender, EventArgs e)
		{
			string s = Clipboard.GetText ();
			if (!checkBoxRegEx.Checked)
				s = Crypt_Pad.Escape (s);
			textFind.Paste (s);
		}

		private void toolStripMenuDelete_Click (object sender, EventArgs e)
		{
			if (0 == textFind.SelectionLength)
				textFind.SelectionLength = 1;
			textFind.Paste ("");
		}

		private void toolStripMenuSelectAll_Click (object sender, EventArgs e)
		{
			textFind.SelectAll ();
		}

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Frank T. Clark
Systems Engineer Three Angels Broadcasting Network
United States United States
I am a Software Systems Design Engineer experienced with IEEE standards and the entire IEEE software development life cycle. Concept Exploration, Requirements, Design, Implementation, Test, Installation and Checkout, Operation and Maintenance. I enjoy working with people and solving customer problems.

I am currently employed as Information Technology Staff in the religious satellite broadcasting industry.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 28 Jul 2014
Article Copyright 2013 by Frank T. Clark
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid