我正在使用C# VSTO创建应用程序级的Word 2010外接程序。我创建了一个用户控件,将控件放在其中,然后使用用户控件添加自定义任务窗格:
UserControl myUserControl;
myUserControl = new PageElementsPane();
mytaskPane = this.CustomTaskPanes.Add
(myUserControl, "Page Elements", doc.ActiveWindow);到目前一切尚好。但是,用户控件包含在自定义任务窗格添加到自定义任务窗格集合后无法访问的列表框。
我已经尝试将列表框上的Modifier属性设置为Public。我尝试将用户控件上的列表框公开为公共属性:
public partial class PageElementsPane: UserControl
{
public ListBox ElementsPaneListBox
{
get { return lbxListbox; }
}
}另外,我看了这篇文章:
Working with ListBox elements in a user control
我希望我能修改它,但是我的列表框IntelliSense没有FindControl,而是提供了FindForm。是否有方法通过将自定义任务窗格解释为窗体来访问用户控件中的列表框?任何帮助都是非常感谢的。
发布于 2015-06-05 16:46:36
似乎我的foreach (因此我的演员)是不正确的(根据尤金·阿斯塔菲耶夫在上面的评论中的问题)。我发现这个SO Post建议循环使用Control类型而不是UserControl类型。我这么做了,一切都很好。以下是代码:
foreach (Control lbxControl in myUserControl.Controls)
{
if (lbxControl is ListBox)
{
((ListBox)lbxControl).SelectedIndex = 1;
}
}https://stackoverflow.com/questions/30631473
复制相似问题