I am trying to create a simple MS Word add-on (mainly for learning functionality). The application adds a custom taskbar and is grouped into a feed. Ribbon controls include a flag to control the visibility of a custom task pane and a button to open a document. When I test the addon in MS Word, the taskbar displays correctly and the checkbox works correctly. The problem is that as soon as I click the button and open a new document, the taskbar is hidden and the checkbox no longer controls the visibility of the taskbar. What is going wrong? How to save the displayed taskbar?
Here is a simple version of addin:
public partial class ThisAddIn { private MyUserControl _myUserControl; private CustomTaskPane _myCustomTastPane; private OpenFileDialog _dialog; private void ThisAddIn_Startup(object sender, System.EventArgs e) { _dialog = new OpenFileDialog { Filter = "Doc File (*.rtf)|*.rtf", RestoreDirectory = true }; _myUserControl = new MyUserControl(); _myCustomTastPane = this.CustomTaskPanes.Add(_myUserControl, "My Task Pane"); _myCustomTastPane.Visible = true; Globals.Ribbons.MyRibbon.ShowPane.Click += ShowClicked; Globals.Ribbons.MyRibbon.LoadDoc.Click += LoadFile; } private void ShowClicked(object sender, RibbonControlEventArgs ribbonControlEventArgs) { _myCustomTastPane.Visible = Globals.Ribbons.MyRibbon.ShowPane.Checked; } void LoadFile(object sender, RibbonControlEventArgs e) { if (_dialog.ShowDialog() != DialogResult.OK) return; object missing = Missing.Value; object myFalse = false; object myTrue = true; object format = WdSaveFormat.wdFormatRTF; object fileToOpen = _dialog.FileName; Application.Documents.Open(ref fileToOpen, ref myFalse, ref myFalse, ref myFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref myTrue, ref myFalse, ref missing, ref missing, ref missing); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } #region VSTO generated code //.... #endregion }
To keep things simple, I didn’t use the definition of the ribbon, as this is really a button and a checkbox. I also do not take into account the definition of MyUserControl, because the contents of the class are not very important (in my demo version I just have a simple class with a label).
guxiyou
source share