本文整理汇总了C#中System.Windows.Forms.ToolStripMenuItem.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripMenuItem.GetType方法的具体用法?C# ToolStripMenuItem.GetType怎么用?C# ToolStripMenuItem.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripMenuItem
的用法示例。
在下文中一共展示了ToolStripMenuItem.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getShortcutText
private string getShortcutText(ToolStripMenuItem mi)
{
var t= (string)mi.GetType().InvokeMember(
@"GetShortcutText",
BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
null,
mi,
new object[] { });
return t;
}
示例2: addmenu
// http://stackoverflow.com/questions/1121441/c-sharp-addeventhandler-using-reflection
private void addmenu(string name, IEnumerable<string> itemarray, object classobject)
{
var menu = new ToolStripMenuItem(name);
bool merge = typeof (MainForm) != classobject.GetType();
if (merge)
menu.MergeAction = MergeAction.MatchOnly;
foreach (string itemtext in itemarray)
{
if (itemtext == "Seperator")
menu.DropDownItems.Add(new ToolStripSeparator());
else
{
var item = new ToolStripMenuItem {Text = itemtext};
EventInfo eventinfo = item.GetType().GetEvent("Click");
// Zoek de string.Format("{0}_Click", itemtext.Replace(" ", "") methode van classobject
MethodInfo methodinfo =
classobject.GetType().GetMethod(string.Format("{0}_Click", itemtext.Replace(" ", "")));
if (methodinfo == null) // Als die niet bestaat.
item.Enabled = false;
else // Anders, voeg een EventHandler toe van het Click event naar die methode.
eventinfo.AddEventHandler(item,
Delegate.CreateDelegate(eventinfo.EventHandlerType, classobject,
methodinfo));
if (merge)
item.MergeAction = MergeAction.Replace;
menu.DropDownItems.Add(item);
itemdictionary.Add(item.Text, item);
}
}
Items.Add(menu);
}