75 lines
2.6 KiB
C#
75 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Remontor
|
|
{
|
|
public static class SMetodForm
|
|
{
|
|
public static void EnableContextMenu(this TextBox tb)
|
|
{
|
|
if (tb.ContextMenuStrip == null)
|
|
{
|
|
ContextMenuStrip cms = new ContextMenuStrip();
|
|
cms.ShowImageMargin = false;
|
|
|
|
ToolStripMenuItem tsmiUndo = new ToolStripMenuItem("Отменить");
|
|
tsmiUndo.Click += (sender, e) => tb.Undo();
|
|
cms.Items.Add(tsmiUndo);
|
|
|
|
cms.Items.Add(new ToolStripSeparator());
|
|
|
|
ToolStripMenuItem tsmiCut = new ToolStripMenuItem("Вырезать");
|
|
tsmiCut.Click += (sender, e) => tb.Cut();
|
|
cms.Items.Add(tsmiCut);
|
|
|
|
ToolStripMenuItem tsmiCopy = new ToolStripMenuItem("Копировать");
|
|
tsmiCopy.Click += (sender, e) => tb.Copy();
|
|
cms.Items.Add(tsmiCopy);
|
|
|
|
ToolStripMenuItem tsmiPaste = new ToolStripMenuItem("Вставить");
|
|
tsmiPaste.Click += (sender, e) => tb.Paste();
|
|
cms.Items.Add(tsmiPaste);
|
|
|
|
ToolStripMenuItem tsmiDelete = new ToolStripMenuItem("Удалить");
|
|
tsmiDelete.Click += (sender, e) => tb.SelectedText = "";
|
|
cms.Items.Add(tsmiDelete);
|
|
|
|
cms.Items.Add(new ToolStripSeparator());
|
|
|
|
ToolStripMenuItem tsmiSelectAll = new ToolStripMenuItem("Выделить все");
|
|
tsmiSelectAll.Click += (sender, e) => tb.SelectAll();
|
|
cms.Items.Add(tsmiSelectAll);
|
|
|
|
|
|
cms.Opening += (sender, e) =>
|
|
{
|
|
tsmiUndo.Enabled = !tb.ReadOnly && tb.CanUndo;
|
|
tsmiCut.Enabled = !tb.ReadOnly && tb.SelectionLength > 0;
|
|
tsmiCopy.Enabled = tb.SelectionLength > 0;
|
|
tsmiPaste.Enabled = !tb.ReadOnly && Clipboard.ContainsText();
|
|
tsmiDelete.Enabled = !tb.ReadOnly && tb.SelectionLength > 0;
|
|
tsmiSelectAll.Enabled = tb.TextLength > 0 && tb.SelectionLength < tb.TextLength;
|
|
};
|
|
|
|
tb.ContextMenuStrip = cms;
|
|
}
|
|
}
|
|
|
|
public static void EnableContextMenu(this NumericUpDown tb)
|
|
{
|
|
if (tb.ContextMenuStrip == null)
|
|
{
|
|
ContextMenuStrip cms = new ContextMenuStrip();
|
|
// cms.ShowImageMargin = false;
|
|
|
|
|
|
tb.ContextMenuStrip = cms;
|
|
}
|
|
}
|
|
}
|
|
}
|