?? searchform.cs
字號:
// DINAMIC XML Editor
//
// Copyright (c) 2002-2003 Dusan Hlavaty
// mailto: duddo@atlas.cz
//
// This software is licensed under the terms of
// GNU General Public license
//
using System;
using System.Windows.Forms;
namespace XML_editor.MyForms
{
/// <summary>
/// Zobrazuje formular, v ktorom sa da vyhladavat
/// </summary>
public class SearchForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBoxFind;
private System.Windows.Forms.Button buttonFind;
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.CheckBox checkCaseSensitive;
private System.Windows.Forms.CheckBox checkSearchUp;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.RadioButton radioFromCursor;
private System.Windows.Forms.RadioButton radioFromTop;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// odkaz na hlavny formular aplikacie
/// </summary>
private MainForm mainForm = null;
// -------------------------------------------------------------------------
/// <summary>
/// odkaz na hlavny formular aplikacie
/// </summary>
public MainForm MainForm
{
get
{
return this.mainForm;
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Inicializuje instanciu <see cref="SearchForm"/>
/// </summary>
public SearchForm(MainForm mainForm)
{
this.mainForm = mainForm;
this.MyInitializeComponent();
}
// -------------------------------------------------------------------------
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
// -------------------------------------------------------------------------
/// <summary>
/// Moj Designer support
/// </summary>
private void MyInitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.buttonFind = new System.Windows.Forms.Button();
this.buttonClose = new System.Windows.Forms.Button();
this.textBoxFind = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.checkCaseSensitive = new System.Windows.Forms.CheckBox();
this.checkSearchUp = new System.Windows.Forms.CheckBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.radioFromCursor = new System.Windows.Forms.RadioButton();
this.radioFromTop = new System.Windows.Forms.RadioButton();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.CausesValidation = false;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Location = new System.Drawing.Point(16, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Find what:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// buttonFind
//
this.buttonFind.CausesValidation = false;
this.buttonFind.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonFind.Location = new System.Drawing.Point(72, 144);
this.buttonFind.Name = "buttonFind";
this.buttonFind.TabIndex = 1;
this.buttonFind.Text = "Find";
this.buttonFind.Click += new System.EventHandler(this.Clicked_buttonFind);
//
// buttonClose
//
this.buttonClose.CausesValidation = false;
this.buttonClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonClose.Location = new System.Drawing.Point(160, 144);
this.buttonClose.Name = "buttonClose";
this.buttonClose.TabIndex = 2;
this.buttonClose.Text = "Close";
this.buttonClose.Click += new System.EventHandler(this.Clicked_buttonClose);
//
// textBoxFind
//
this.textBoxFind.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBoxFind.Location = new System.Drawing.Point(72, 16);
this.textBoxFind.Name = "textBoxFind";
this.textBoxFind.Size = new System.Drawing.Size(224, 20);
this.textBoxFind.TabIndex = 0;
this.textBoxFind.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.checkSearchUp,
this.checkCaseSensitive});
this.groupBox2.Location = new System.Drawing.Point(160, 56);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(136, 80);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Options";
//
// checkCaseSensitive
//
this.checkCaseSensitive.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.checkCaseSensitive.Location = new System.Drawing.Point(16, 24);
this.checkCaseSensitive.Name = "checkCaseSensitive";
this.checkCaseSensitive.TabIndex = 7;
this.checkCaseSensitive.Text = "Case &sensitive";
//
// checkSearchUp
//
this.checkSearchUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.checkSearchUp.Location = new System.Drawing.Point(16, 48);
this.checkSearchUp.Name = "checkSearchUp";
this.checkSearchUp.TabIndex = 8;
this.checkSearchUp.Text = "S&earch up";
//
// groupBox3
//
this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioFromCursor,
this.radioFromTop});
this.groupBox3.Location = new System.Drawing.Point(16, 56);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(136, 80);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Origin";
//
// radioFromCursor
//
this.radioFromCursor.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.radioFromCursor.Location = new System.Drawing.Point(16, 24);
this.radioFromCursor.Name = "radioFromCursor";
this.radioFromCursor.TabIndex = 3;
this.radioFromCursor.Text = "From &cursor";
//
// radioFromTop
//
this.radioFromTop.Checked = true;
this.radioFromTop.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.radioFromTop.Location = new System.Drawing.Point(16, 48);
this.radioFromTop.Name = "radioFromTop";
this.radioFromTop.TabIndex = 4;
this.radioFromTop.TabStop = true;
this.radioFromTop.Text = "From the &top";
//
// SearchForm
//
this.AcceptButton = this.buttonFind;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.buttonClose;
this.ClientSize = new System.Drawing.Size(306, 175);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox3,
this.groupBox2,
this.textBoxFind,
this.buttonClose,
this.buttonFind,
this.label1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ControlBox = false;
this.Name = "SearchForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Find Text";
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
// -------------------------------------------------------------------------
/// <summary>
/// Stlacenie tlacidla CLOSE
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Clicked_buttonClose(object sender, System.EventArgs e)
{
this.Hide();
}
// -------------------------------------------------------------------------
/// <summary>
/// Stlacenie tlacidla FIND
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Clicked_buttonFind(object sender, System.EventArgs e)
{
int searchFrom;
if (this.MainForm.ActualTextAreaControl == null)
{
return;
}
if (this.checkSearchUp.Checked == true)
{
searchFrom = this.MainForm.ActualTextAreaControl.Document.TextLength - 1;
}
else
{
searchFrom = 0;
}
if (this.radioFromCursor.Checked == true)
{
searchFrom = this.MainForm.ActualTextAreaControl.Document.Caret.Offset;
}
this.Find(searchFrom, this.checkSearchUp.Checked, this.textBoxFind.Text, this.checkCaseSensitive.Checked);
this.radioFromCursor.Checked = true;
this.radioFromTop.Checked = false;
this.Hide();
}
// -------------------------------------------------------------------------
/// <summary>
/// Najde zadany retazec v dokumente.
/// </summary>
/// <param name="startHere">na tomto offsete zacni hladat</param>
/// <param name="searchUp"><c>true</c> = hladame smerom dolu, inac <c>false</c></param>
/// <param name="findThis">tento retazec hladaj</param>
/// <param name="caseSensitive"><c>true</c> = case sensitive</param>
private void Find(int startHere, bool searchUp, string findThis, bool caseSensitive)
{
int position = -1;
if (searchUp == false)
{
position = DLTextEditor.Document.TextUtilities.FindNextString(this.MainForm.ActualTextAreaControl.Document, startHere+1, this.textBoxFind.Text, this.checkCaseSensitive.Checked);
if (position < 0)
{
MessageBox.Show("Search string '" + findThis + "' not found.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else
{
position = DLTextEditor.Document.TextUtilities.FindPreviousString(this.MainForm.ActualTextAreaControl.Document, startHere-1, this.textBoxFind.Text, this.checkCaseSensitive.Checked);
if (position < 0)
{
MessageBox.Show("Search string '" + findThis + "' not found.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
this.MainForm.ActualTextAreaControl.JumpTo(position);
DLTextEditor.Document.SelectionManager.DefaultSelection s = new DLTextEditor.Document.SelectionManager.DefaultSelection(this.MainForm.ActualTextAreaControl.Document, position, findThis.Length);
this.MainForm.ActualTextAreaControl.Document.ClearSelection();
this.MainForm.ActualTextAreaControl.Document.SetSelection(s);
this.MainForm.ActualTextAreaControl.Focus();
}
} // public class SearchForm : ...
} // namespace XML_editor.MyForms
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -