findreplaceform.cs
来自「一个很好用的html编辑器。带源码」· CS 代码 · 共 456 行 · 第 1/2 页
CS
456 行
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace Microsoft.ConsultingServices.HtmlEditor
{
/// <summary>
/// Form designed to control Find and Replace operations
/// Find and Replace operations performed by the user control class
/// Delegates need to be defined to reference the class instances
/// </summary>
internal class FindReplaceForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TabPage tabFind;
private System.Windows.Forms.TabPage tabReplace;
private System.Windows.Forms.Label labelFind;
private System.Windows.Forms.TabControl tabControl;
private System.Windows.Forms.Button bCancel;
private System.Windows.Forms.TextBox textFind;
private System.Windows.Forms.Button bFindNext;
private System.Windows.Forms.Label labelReplace;
private System.Windows.Forms.Button bReplaceAll;
private System.Windows.Forms.Button bReplace;
private System.Windows.Forms.Button bOptions;
private System.Windows.Forms.CheckBox optionMatchCase;
private System.Windows.Forms.CheckBox optionMatchWhole;
private System.Windows.Forms.TextBox textReplace;
private System.Windows.Forms.Panel panelOptions;
private System.Windows.Forms.Panel panelInput;
private System.ComponentModel.Container components = null;
// private variables defining the state of the form
private bool options = false;
private bool findNotReplace = true;
private string findText;
private string replaceText;
// internal delegate reference
private FindReplaceResetDelegate FindReplaceReset;
private FindReplaceOneDelegate FindReplaceOne;
private FindReplaceAllDelegate FindReplaceAll;
private FindFirstDelegate FindFirst;
private FindNextDelegate FindNext;
// public constructor that defines the required delegates
// delegates must be defined for the find and replace to operate
public FindReplaceForm(string initText, FindReplaceResetDelegate resetDelegate, FindFirstDelegate findFirstDelegate, FindNextDelegate findNextDelegate, FindReplaceOneDelegate replaceOneDelegate, FindReplaceAllDelegate replaceAllDelegate)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// Define the initial state of the form assuming a Find command to be displayed first
DefineFindWindow(findNotReplace);
DefineOptionsWindow(options);
// ensure buttons not initially enabled
this.bFindNext.Enabled = false;
this.bReplace.Enabled = false;
this.bReplaceAll.Enabled = false;
// save the delegates used to perform find and replcae operations
this.FindReplaceReset = resetDelegate;
this.FindFirst = findFirstDelegate;
this.FindNext = findNextDelegate;
this.FindReplaceOne = replaceOneDelegate;
this.FindReplaceAll = replaceAllDelegate;
// define the original text
this.textFind.Text = initText;
} //FindReplaceForm
// setup the properties based on the find or repalce functionality
private void DefineFindWindow(bool find)
{
this.textReplace.Visible = !find;
this.labelReplace.Visible = !find;
this.bReplace.Visible = !find;
this.bReplaceAll.Visible = !find;
this.textFind.Focus();
} //DefineFindWindow
// define if the options dialog is shown
private void DefineOptionsWindow(bool options)
{
if (options)
{
// Form displayed with the options shown
this.bOptions.Text = "Less Options";
this.panelOptions.Visible = true;
this.tabControl.Height = 216;
this.Height = 264;
this.optionMatchCase.Focus();
}
else
{
// Form displayed without the options shown
this.bOptions.Text = "More Options";
this.panelOptions.Visible = false;
this.tabControl.Height = 152;
this.Height = 200;
this.textFind.Focus();
}
} //DefineOptionsWindow
// Clean up any resources being used.
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} //Dispose
#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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FindReplaceForm));
this.tabControl = new System.Windows.Forms.TabControl();
this.tabFind = new System.Windows.Forms.TabPage();
this.tabReplace = new System.Windows.Forms.TabPage();
this.labelFind = new System.Windows.Forms.Label();
this.bCancel = new System.Windows.Forms.Button();
this.textFind = new System.Windows.Forms.TextBox();
this.bFindNext = new System.Windows.Forms.Button();
this.labelReplace = new System.Windows.Forms.Label();
this.textReplace = new System.Windows.Forms.TextBox();
this.bReplaceAll = new System.Windows.Forms.Button();
this.bReplace = new System.Windows.Forms.Button();
this.bOptions = new System.Windows.Forms.Button();
this.optionMatchCase = new System.Windows.Forms.CheckBox();
this.optionMatchWhole = new System.Windows.Forms.CheckBox();
this.panelOptions = new System.Windows.Forms.Panel();
this.panelInput = new System.Windows.Forms.Panel();
this.tabControl.SuspendLayout();
this.panelOptions.SuspendLayout();
this.panelInput.SuspendLayout();
this.SuspendLayout();
//
// tabControl
//
this.tabControl.Controls.Add(this.tabFind);
this.tabControl.Controls.Add(this.tabReplace);
this.tabControl.Location = new System.Drawing.Point(8, 8);
this.tabControl.Name = "tabControl";
this.tabControl.SelectedIndex = 0;
this.tabControl.ShowToolTips = true;
this.tabControl.Size = new System.Drawing.Size(440, 32);
this.tabControl.TabIndex = 0;
this.tabControl.TabStop = false;
this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged);
//
// tabFind
//
this.tabFind.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.tabFind.Location = new System.Drawing.Point(4, 22);
this.tabFind.Name = "tabFind";
this.tabFind.Size = new System.Drawing.Size(432, 6);
this.tabFind.TabIndex = 0;
this.tabFind.Text = "Find";
this.tabFind.ToolTipText = "Find Text";
//
// tabReplace
//
this.tabReplace.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.tabReplace.Location = new System.Drawing.Point(4, 22);
this.tabReplace.Name = "tabReplace";
this.tabReplace.Size = new System.Drawing.Size(432, 6);
this.tabReplace.TabIndex = 1;
this.tabReplace.Text = "Replace";
this.tabReplace.ToolTipText = "Find and Replace Text";
//
// labelFind
//
this.labelFind.Location = new System.Drawing.Point(8, 16);
this.labelFind.Name = "labelFind";
this.labelFind.Size = new System.Drawing.Size(96, 23);
this.labelFind.TabIndex = 0;
this.labelFind.Text = "Find What:";
//
// bCancel
//
this.bCancel.BackColor = System.Drawing.SystemColors.Control;
this.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.bCancel.Location = new System.Drawing.Point(344, 80);
this.bCancel.Name = "bCancel";
this.bCancel.TabIndex = 4;
this.bCancel.Text = "Cancel";
//
// textFind
//
this.textFind.Location = new System.Drawing.Point(112, 16);
this.textFind.Name = "textFind";
this.textFind.Size = new System.Drawing.Size(296, 20);
this.textFind.TabIndex = 1;
this.textFind.Text = "";
this.textFind.TextChanged += new System.EventHandler(this.textFind_TextChanged);
//
// bFindNext
//
this.bFindNext.BackColor = System.Drawing.SystemColors.Control;
this.bFindNext.Location = new System.Drawing.Point(264, 80);
this.bFindNext.Name = "bFindNext";
this.bFindNext.TabIndex = 3;
this.bFindNext.Text = "Find Next";
this.bFindNext.Click += new System.EventHandler(this.bFindNext_Click);
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?