本文整理汇总了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;
}