138 lines
5.7 KiB
C#
138 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace ryProcessManager.hezuo
|
|
{
|
|
public partial class ContextMenuStripHighlightText : ContextMenuStrip
|
|
{
|
|
public ContextMenuStripHighlightText()
|
|
{
|
|
InitializeComponent();
|
|
AddMenu("撤销", "undo").Click += Undo_Click;
|
|
AddMenu("重做", "redo").Click += Redo_Click;
|
|
AddSeparatorMenu();
|
|
AddMenu("剪切", "cut").Click += Cut_Click;
|
|
AddMenu("复制", "copy").Click += Copy_Click;
|
|
AddMenu("粘贴", "paste").Click += Paste_Click;
|
|
AddMenu("删除", "del").Click += Del_Click;
|
|
AddMenu("全选", "selectall").Click += SelectAll_Click;
|
|
AddMenu("查找", "find").Click += Find_Click;
|
|
}
|
|
private void Find_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.ShowFindDialog();
|
|
}
|
|
private void SelectAll_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.SelectAll();
|
|
//Thread th = new Thread(sendkey);
|
|
//th.Start();
|
|
//void sendkey()
|
|
//{
|
|
// Thread.Sleep(100);
|
|
// this.Invoke(new Action(() =>
|
|
// {
|
|
// SendKeys.SendWait("^a");
|
|
// }));
|
|
//}
|
|
}
|
|
private void Undo_Click(object sender, EventArgs e)
|
|
{
|
|
if(!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.Undo();
|
|
}
|
|
private void Redo_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.Redo();
|
|
}
|
|
private void Cut_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.Cut();
|
|
}
|
|
private void Copy_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
var ss = rich_txt.SelectedText;
|
|
rich_txt.Copy();
|
|
}
|
|
private void Paste_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.Paste();
|
|
}
|
|
private void Del_Click(object sender, EventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
rich_txt.SelectedText="";
|
|
}
|
|
public ToolStripSeparator AddSeparatorMenu()
|
|
{
|
|
ToolStripSeparator item = new ToolStripSeparator();
|
|
base.Items.Add(item);
|
|
return item;
|
|
}
|
|
public ToolStripMenuItem AddMenu(string name, string tag)
|
|
{
|
|
ToolStripMenuItem item = new ToolStripMenuItem(name)
|
|
{
|
|
Tag = tag
|
|
};
|
|
base.Items.Add(item);
|
|
return item;
|
|
}
|
|
|
|
private void ContextMenuStripRichText_Opening(object sender, CancelEventArgs e)
|
|
{
|
|
if (!(base.SourceControl is FastColoredTextBoxNS.FastColoredTextBox)) { return; }
|
|
var rich_txt = (FastColoredTextBoxNS.FastColoredTextBox)base.SourceControl;
|
|
for (int i = 0; i < base.Items.Count; i++)
|
|
{
|
|
var item = base.Items[i];
|
|
if (item.Tag == null) { continue; }
|
|
switch(item.Tag.ToString())
|
|
{
|
|
case "undo":
|
|
item.Enabled = rich_txt.UndoEnabled && !rich_txt.ReadOnly;
|
|
break;
|
|
case "redo":
|
|
item.Enabled = rich_txt.RedoEnabled && !rich_txt.ReadOnly;
|
|
break;
|
|
case "cut":
|
|
item.Enabled = (rich_txt.SelectedText != "" && !rich_txt.ReadOnly) ? true : false;
|
|
break;
|
|
case "copy":
|
|
item.Enabled = rich_txt.SelectedText != "" ? true : false;
|
|
break;
|
|
case "paste":
|
|
item.Enabled = !rich_txt.ReadOnly;
|
|
break;
|
|
case "del":
|
|
item.Enabled =(rich_txt.SelectedText != "" && !rich_txt.ReadOnly) ? true : false;
|
|
break;
|
|
case "selectall":
|
|
item.Enabled = rich_txt.SelectedText != rich_txt.Text ? true : false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|