Find/Replace Dialog Component

Enables Windows Forms applications to use a find / replace dialog.

C# (39.4 KB)
 
 
 
 
 
(0)
2,817 times
Add to favorites
3/1/2011
E-mail Twitter del.icio.us Digg Facebook
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Demo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private CP.Window.Forms.FindReplaceDialog findReplaceDialog1;
		private System.Windows.Forms.PropertyGrid propertyGrid1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button showDialog;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.findReplaceDialog1 = new CP.Window.Forms.FindReplaceDialog();
			this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.showDialog = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// findReplaceDialog1
			// 
			this.findReplaceDialog1.Direction = CP.Window.Forms.FindDirection.Up;
			this.findReplaceDialog1.DisableMatchCase = false;
			this.findReplaceDialog1.DisableUpDown = false;
			this.findReplaceDialog1.DisableWholeWord = false;
			this.findReplaceDialog1.FindWhat = "Tesrt";
			this.findReplaceDialog1.HideMatchCase = false;
			this.findReplaceDialog1.HideUpDown = false;
			this.findReplaceDialog1.HideWholeWord = false;
			this.findReplaceDialog1.MatchCase = false;
			this.findReplaceDialog1.MatchWholeWord = false;
			this.findReplaceDialog1.ReplaceWith = "Try";
			this.findReplaceDialog1.ShowHelp = false;
			this.findReplaceDialog1.Type = CP.Window.Forms.FindReplaceDialogType.Find;
			this.findReplaceDialog1.ReplaceAll += new System.EventHandler(this.findReplaceDialog1_ReplaceAll);
			this.findReplaceDialog1.FindNext += new System.EventHandler(this.findReplaceDialog1_FindNext);
			this.findReplaceDialog1.DialogTerminate += new System.EventHandler(this.findReplaceDialog1_DialogTerminate);
			this.findReplaceDialog1.Replace += new System.EventHandler(this.findReplaceDialog1_Replace);
			// 
			// propertyGrid1
			// 
			this.propertyGrid1.CommandsVisibleIfAvailable = true;
			this.propertyGrid1.LargeButtons = false;
			this.propertyGrid1.LineColor = System.Drawing.SystemColors.ScrollBar;
			this.propertyGrid1.Name = "propertyGrid1";
			this.propertyGrid1.Size = new System.Drawing.Size(176, 310);
			this.propertyGrid1.TabIndex = 0;
			this.propertyGrid1.Text = "propertyGrid1";
			this.propertyGrid1.ViewBackColor = System.Drawing.SystemColors.Window;
			this.propertyGrid1.ViewForeColor = System.Drawing.SystemColors.WindowText;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(176, 40);
			this.textBox1.Multiline = true;
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(290, 275);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// showDialog
			// 
			this.showDialog.Location = new System.Drawing.Point(274, 8);
			this.showDialog.Name = "showDialog";
			this.showDialog.Size = new System.Drawing.Size(90, 23);
			this.showDialog.TabIndex = 2;
			this.showDialog.Text = "Show Dialog";
			this.showDialog.Click += new System.EventHandler(this.showDialog_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(466, 307);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.showDialog,
																		  this.textBox1,
																		  this.propertyGrid1});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion
	
		public static void Main(string[] args)
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			findReplaceDialog1.ShowDialog(this);
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			propertyGrid1.SelectedObject = findReplaceDialog1;
		}

		private void findReplaceDialog1_DialogTerminate(object sender, System.EventArgs e)
		{
			textBox1.AppendText("Dialog Terminate\r\n");
			showDialog.Enabled = true;
		}

		private void findReplaceDialog1_FindNext(object sender, System.EventArgs e)
		{
			textBox1.AppendText(String.Format("Event : FindNext Text={0} Direction={1}\r\n", findReplaceDialog1.FindWhat, findReplaceDialog1.Direction));
		}

		private void findReplaceDialog1_HelpRequest(object sender, System.EventArgs e)
		{
			textBox1.AppendText(String.Format("Event : Help Request\r\n"));
		}

		private void findReplaceDialog1_Replace(object sender, System.EventArgs e)
		{
			textBox1.AppendText(String.Format("Event : Replace Text = {0} Replace Text={1} Direction={2}\r\n", findReplaceDialog1.FindWhat, findReplaceDialog1.ReplaceWith, findReplaceDialog1.Direction));
		}

		private void findReplaceDialog1_ReplaceAll(object sender, System.EventArgs e)
		{
			textBox1.AppendText(String.Format("Event : ReplaceAll Text = {0} Replace Text={1} Direction={2}\r\n", findReplaceDialog1.FindWhat, findReplaceDialog1.ReplaceWith, findReplaceDialog1.Direction));
		}

		private void showDialog_Click(object sender, System.EventArgs e)
		{
			showDialog.Enabled = false;
			findReplaceDialog1.ShowDialog(this);
		}
	}
}