![]() |
| If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|||||||
| Tags: bar, command, error, position, saving, settings |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
My Outlook add-in code is breaking when attempting to save the command bar
position. Complete code for the add-in appears below. This is built in Visual Studio 2008 for Outlook 2007. Also, the Settings.settings properties are as follows: CommandBarTop, int, 0 CommandBarLeft, int, 0 CommandBarVisible, bool, True CommandBarPosition, 4 CommandBarRowIndex, 1 Everything works so far, except when the ThisAddIn_Shutdown() event calls SaveCommandBarSettings(). Debugger shows that code fails when it hits commandBar.Top. Below are some error details. What's a little disturbing is that it appears that a method which is internal to Microsoft Office is the point of failure. Microsoft.Office.Core.CommandBar.get_Top() Perhaps I need to repair Office (yet again). I repaired Office 2007 Ultimate once before when troubleshooting a completely different issue that was caused by Visual Studio 2008 Power Tools. ===================================== Exception from HRESULT: 0x800A01A8 System.Runtime.InteropServices.COMException was unhandled Message="Exception from HRESULT: 0x800A01A8" Source="office" ErrorCode=-2146827864 StackTrace: at Microsoft.Office.Core.CommandBar.get_Top() InnerException: ===================================== Any assistance would be appreciated. Again, the complete code is pasted below so you can try to replicate the problem. Thanks for your help. Ken ======================================== using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using Outlook = Microsoft.Office.Interop.Outlook; using Office = Microsoft.Office.Core; namespace OutlookHW { /// summary /// Adapted from the following: /// http://msdn.microsoft.com/en-us/library/cc136646.aspx /// http://msdn.microsoft.com/en-us/library/ms268891.aspx /// /summary /// remarks /// 6/10/2008 - Ken Palmer - Created /// /remarks public partial class ThisAddIn { #region Hello World // Create the command bar variables at the class level. Office.CommandBar commandBar; Office.CommandBarButton firstButton; Office.CommandBarButton secondButton; private void ThisAddIn_Startup(object sender, System.EventArgs e) { AddToolbar(); LoadCommandBarSettings(); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { SaveCommandBarSettings(); } private void AddToolbar() { Outlook.Explorer myExplorer; myExplorer = this.Application.ActiveExplorer(); try { commandBar = myExplorer.CommandBars["Test"]; } catch (ArgumentException e) { // Toolbar named Test does not exist so we should create it. } if (commandBar == null) { // Add a commandbar named Test. commandBar = myExplorer.CommandBars.Add("Test", 1, missing, true); } try { // Add a button to the command bar and an event handler. firstButton = (Office.CommandBarButton)commandBar.Controls.Add(1 , missing, missing, missing, missing); firstButton.Style = Office.MsoButtonStyle.msoButtonCaption; firstButton.Caption = "Hello"; firstButton.Tag = "btnHello"; firstButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(firstButton_Click); // Add a second button to the command bar and an event handler. secondButton = (Office.CommandBarButton)commandBar.Controls.Add(1 , missing, missing, missing, missing); secondButton.Style = Office.MsoButtonStyle.msoButtonCaption; secondButton.Caption = "World"; secondButton.Tag = "btnWorld"; secondButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(secondButton_Click); commandBar.Visible = true; } catch (ArgumentException e) { MessageBox.Show(e.Message); } } void secondButton_Click(Microsoft.Office.Core.CommandBa rButton Ctrl, ref bool CancelDefault) { MessageBox.Show("2nd button clicked: World"); } void firstButton_Click(Microsoft.Office.Core.CommandBar Button Ctrl, ref bool CancelDefault) { MessageBox.Show("1st button clicked: Hello"); } #region Load Command Bar Settings private void LoadCommandBarSettings() { Microsoft.Office.Core.MsoBarPosition position = (Microsoft.Office.Core.MsoBarPosition)Properties.S ettings .Default["CommandBarPosition"]; commandBar.Position = position; int rowIndex = Convert.ToInt32(Properties.Settings.Default["CommandBarRowIndex"]); commandBar.RowIndex = rowIndex; int top = Convert.ToInt32(Properties.Settings.Default["CommandBarTop"]); commandBar.Top = top != 0 ? top : Screen.PrimaryScreen.Bounds.Height / 2; int left = Convert.ToInt32(Properties.Settings.Default["CommandBarLeft"]); commandBar.Left = left != 0 ? left : Screen.PrimaryScreen.Bounds.Width / 2; bool visible = Convert.ToBoolean(Properties.Settings.Default["CommandBarVisible"]); commandBar.Visible = visible; } #endregion private void SaveCommandBarSettings() { try { if (commandBar != null) { MessageBox.Show(commandBar.Top.ToString()); } if (commandBar != null) { Properties.Settings.Default["CommandBarTop"] = commandBar.Top; } Properties.Settings.Default["CommandBarLeft"] = commandBar.Left; Properties.Settings.Default["CommandBarVisible"] = commandBar.Visible; Properties.Settings.Default["CommandBarPosition"] = (int)commandBar.Position; Properties.Settings.Default["CommandBarRowIndex"] = commandBar.RowIndex; Properties.Settings.Default.Save(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } #endregion #region VSTO generated code /// summary /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// /summary private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } } |
| Ads |
|
#2
|
|||
|
|||
|
This is solved. McLean Schofield from Microsoft was able to point me in the
right direction at the following forum. The coded solution is posted there as well. http://forums.microsoft.com/MSDN/Sho...74456&SiteID=1 |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Settings for Saving Contact Information | Shane Tanouye | Outlook - Using Contacts | 1 | July 26th 07 02:15 PM |
| Saving OE Settings | Willy | Outlook Express | 14 | March 4th 07 09:16 PM |
| Saving commanbar position in shared add-in | ian | Add-ins for Outlook | 1 | September 1st 06 08:10 PM |
| How to find easily position of script error? | Sabine | Outlook Express | 2 | February 15th 06 05:36 PM |
| Saving User Settings in Outlook... | Ismael | Outlook - General Queries | 2 | January 20th 06 07:34 PM |