我在做Winform多语言开发时遇到错误
Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'.
求高手指点,这种错误怎么解决!
...全文
16410打赏收藏
Winform 多语言开发,求助!!!
我在做Winform多语言开发时遇到错误 Unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'. 求高手指点,这种错误怎么解决!
/// <summary>
/// Application resources
/// ApplyResources first parameter to set the control
/// The second parameter for the ID in the resource file, and defaults to the name of the control
/// </summary>
private void ApplyResource()
{
System.ComponentModel.ComponentResourceManager res = new ComponentResourceManager(typeof(Form1));
foreach (Control ctl in Controls)
{
res.ApplyResources(ctl, ctl.Name);
}
//Menu
foreach (ToolStripMenuItem item in this.menuStrip1.Items)
{
res.ApplyResources(item, item.Name);
foreach (ToolStripMenuItem subItem in item.DropDownItems)
{
res.ApplyResources(subItem, subItem.Name);
}
}
//Caption
res.ApplyResources(this, "$this");
}