📄 replace.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace myTest
{
/// <summary>
/// replace 的摘要说明。
/// </summary>
public class replace : System.Windows.Forms.Form
{
private System.Windows.Forms.Label inputLabel;
private System.Windows.Forms.TextBox inputBox;
private System.Windows.Forms.Label inputReplace;
private System.Windows.Forms.TextBox inputReplaceWords;
private System.Windows.Forms.Button sureButton;
private System.Windows.Forms.Button concelButton;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
myText MainForm1;
int lacation = 0;//替换位置
public replace(myText form1)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
MainForm1 = form1;
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(replace));
this.inputLabel = new System.Windows.Forms.Label();
this.inputBox = new System.Windows.Forms.TextBox();
this.inputReplace = new System.Windows.Forms.Label();
this.inputReplaceWords = new System.Windows.Forms.TextBox();
this.sureButton = new System.Windows.Forms.Button();
this.concelButton = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// inputLabel
//
this.inputLabel.BackColor = System.Drawing.Color.SkyBlue;
this.inputLabel.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.inputLabel.Location = new System.Drawing.Point(16, 8);
this.inputLabel.Name = "inputLabel";
this.inputLabel.Size = new System.Drawing.Size(72, 16);
this.inputLabel.TabIndex = 0;
this.inputLabel.Text = "查找内容";
//
// inputBox
//
this.inputBox.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.inputBox.Location = new System.Drawing.Point(96, 8);
this.inputBox.Name = "inputBox";
this.inputBox.Size = new System.Drawing.Size(184, 21);
this.inputBox.TabIndex = 1;
this.inputBox.Text = "";
//
// inputReplace
//
this.inputReplace.BackColor = System.Drawing.Color.SkyBlue;
this.inputReplace.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.inputReplace.Location = new System.Drawing.Point(16, 72);
this.inputReplace.Name = "inputReplace";
this.inputReplace.Size = new System.Drawing.Size(72, 16);
this.inputReplace.TabIndex = 2;
this.inputReplace.Text = "替换为";
//
// inputReplaceWords
//
this.inputReplaceWords.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.inputReplaceWords.Location = new System.Drawing.Point(96, 72);
this.inputReplaceWords.Name = "inputReplaceWords";
this.inputReplaceWords.Size = new System.Drawing.Size(184, 21);
this.inputReplaceWords.TabIndex = 3;
this.inputReplaceWords.Text = "";
//
// sureButton
//
this.sureButton.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.sureButton.Image = ((System.Drawing.Image)(resources.GetObject("sureButton.Image")));
this.sureButton.Location = new System.Drawing.Point(296, 8);
this.sureButton.Name = "sureButton";
this.sureButton.TabIndex = 4;
this.sureButton.Click += new System.EventHandler(this.sureButton_Click);
//
// concelButton
//
this.concelButton.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.concelButton.Image = ((System.Drawing.Image)(resources.GetObject("concelButton.Image")));
this.concelButton.Location = new System.Drawing.Point(296, 40);
this.concelButton.Name = "concelButton";
this.concelButton.TabIndex = 5;
this.concelButton.Click += new System.EventHandler(this.concelButton_Click);
//
// button1
//
this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));
this.button1.Location = new System.Drawing.Point(296, 72);
this.button1.Name = "button1";
this.button1.TabIndex = 6;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// replace
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(384, 109);
this.Controls.Add(this.button1);
this.Controls.Add(this.concelButton);
this.Controls.Add(this.sureButton);
this.Controls.Add(this.inputReplaceWords);
this.Controls.Add(this.inputBox);
this.Controls.Add(this.inputReplace);
this.Controls.Add(this.inputLabel);
this.Name = "replace";
this.Text = "replace";
this.ResumeLayout(false);
}
#endregion
private void sureButton_Click(object sender, System.EventArgs e)
{
if(inputBox.Text.Length==0)//如果查找字符串为空
MessageBox.Show("查找字符串不能为空","提示",MessageBoxButtons.OK);
else
{
lacation = MainForm1.FindRichTextBoxString(inputBox.Text);//上步增加的方法
}
}
private void concelButton_Click(object sender, System.EventArgs e)
{
if(lacation==0)
MessageBox.Show("先要查找到替换字符","提示",MessageBoxButtons.OK);
else
MainForm1.ReplaceRichTextBoxString(inputReplaceWords.Text,inputBox.Text);
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -