本文整理匯總了C#中System.Windows.Forms.TextBox.AppendTextToSelection方法的典型用法代碼示例。如果您正苦於以下問題:C# TextBox.AppendTextToSelection方法的具體用法?C# TextBox.AppendTextToSelection怎麽用?C# TextBox.AppendTextToSelection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.AppendTextToSelection方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateCodesMenu
public static ContextMenuStrip CreateCodesMenu(TextBox tb, params ReplacementVariables[] ignoreList)
{
ContextMenuStrip cms = new ContextMenuStrip
{
Font = new XmlFont("Lucida Console", 8),
AutoClose = false,
Opacity = 0.9,
ShowImageMargin = false
};
var variables = Enum.GetValues(typeof(ReplacementVariables)).Cast<ReplacementVariables>().Where(x => !ignoreList.Contains(x)).
Select(x => new
{
Name = ReplacementExtension.Prefix + Enum.GetName(typeof(ReplacementVariables), x),
Description = x.GetDescription(),
Enum = x
});
foreach (var variable in variables)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name };
tsmi.Click += (sender, e) =>
{
string text = ((ToolStripMenuItem)sender).Tag.ToString();
tb.AppendTextToSelection(text);
};
cms.Items.Add(tsmi);
}
cms.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiClose = new ToolStripMenuItem("Close");
tsmiClose.Click += (sender, e) => cms.Close();
cms.Items.Add(tsmiClose);
tb.MouseDown += (sender, e) =>
{
if (cms.Items.Count > 0) cms.Show(tb, new Point(tb.Width + 1, 0));
};
tb.Leave += (sender, e) =>
{
if (cms.Visible) cms.Close();
};
tb.KeyDown += (sender, e) =>
{
if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && cms.Visible)
{
cms.Close();
e.SuppressKeyPress = true;
}
};
tb.Disposed += (sender, e) => cms.Dispose();
return cms;
}