管理侧栏——Word 2007高级应用(九)
2008-10-14 20:18:23 来源:WEB开发网增值服务区
Managing Custom Task Panes in Multiple Application Windows
另一种办法就是,当用户点击My Blogs按钮时判断当前窗口是否有与之关联的侧边栏,有则显示,无则创建并显示。而侧边栏的销毁则与上一种办法相同。
接下来,我将采用第二种办法来管理"我的博客"侧边栏,稍稍不同的是,我会把侧边栏的创建/获取和销毁等工作外包给MyBlogsPaneManager类而不是直接放在相关的Event Handler里。
// Code #02
MyBlogsPaneManager#region MyBlogsPaneManager
public class MyBlogsPaneManager
{
private MyBlogsPaneManager()
{
m_MyBlogsPanes = Globals.ThisAddIn.CustomTaskPanes;
}
private static MyBlogsPaneManager m_Instance = new MyBlogsPaneManager();
public static MyBlogsPaneManager Instance
{
get { return m_Instance; }
}
private Vsto.CustomTaskPaneCollection m_MyBlogsPanes;
public Vsto.CustomTaskPane GetMyBlogsPane()
{
Word.Window window = Globals.ThisAddIn.Application.ActiveWindow;
foreach (Vsto.CustomTaskPane ctp in m_MyBlogsPanes)
{
if (ctp.Title == "My Blogs" && ctp.Window == window)
{
return ctp;
}
}
return m_MyBlogsPanes.Add(
new MyBlogsUserControl(),
"My Blogs",
window
);
}
public void CollectMyBlogsPanes()
{
for (int i = m_MyBlogsPanes.Count - 1; i >= 0; i--)
{
if (m_MyBlogsPanes[i].Window == null)
{
m_MyBlogsPanes.RemoveAt(i);
}
}
}
}
#endregion
更多精彩
赞助商链接