searchandmark.cs
来自「自己做的一个浏览器~~大家请看看~如果合意给个彩头」· CS 代码 · 共 70 行
CS
70 行
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace WebPort.Tools
{
public partial class SearchAndMark : ToolStrip
{
public SearchAndMark()
{
InitializeComponent();
}
private void Mark(string text, string fore, string bg)
{
MainForm main = this.FindForm() as MainForm;
if (main != null)
{
try
{
HtmlDocument doc = main.GetDocument();
string func = string.Format("highlight_{0}", Guid.NewGuid().ToString().Replace("-", ""));
string code = string.Format(@"function {0}(text)
{{
var r=document.body.createTextRange();
while(r.findText(text))
{{
r.execCommand('BackColor','','{1}');
r.execCommand('ForeColor','','{2}');
r.execCommand('Bold','','');
r.collapse(false);
}}
}}", func, bg, fore);
Script script = new Script(doc);
script.Execute(code, null);
script.Invoke(func, text);
}
catch
{
}
}
}
private void tsGo_Click(object sender, EventArgs e)
{
Mark(tsText.Text, "red", "yellow");
}
private void tsText_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
tsText.SelectAll();
tsGo_Click(tsGo, EventArgs.Empty);
e.Handled = true;
}
}
private void tsText_Enter(object sender, EventArgs e)
{
tsText.Focus();
tsText.SelectAll();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?