A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VSTO Outlook 2003 - Issue with button event handlers



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 20th 07, 12:02 AM posted to microsoft.public.outlook.program_addins
Soumitra
external usenet poster
 
Posts: 1
Default VSTO Outlook 2003 - Issue with button event handlers

Hi,

I am developing a VSTO add-in for Outlook 2003 using VS. NET 2005 VSTO
template. I am adding two command buttons to Outlook's standard tool
bar. These buttons are hooked up to an event handler
(Button1_Click). When I start outlook I see the two buttons, however
for some reason only one button is hooked to the event handler. This
does not depend on the order in which the buttons are created. There
seems to be no patter to this. Sometimes event handler for both
buttons work. But usually the event handler for the button that is
clicked first works. To me it seems like Outlook disposes the second
button for some reason. I have pasted the code inside ThisAddIn.cs
below. In this code the two buttons are added to two separate Popup.
However, the result is same as directly adding the buttons to the
standard tool bar.

Please let me know if anyone has any thoughts on this.

Thanks,
Soumitra Mishra

namespace IssueEmailAddIn2003
{
public partial class ThisAddIn
{
private Microsoft.Office.Interop.Outlook.Selection
currentSelection;
public Microsoft.Office.Interop.Outlook.Selection
CurrentSelection
{
get { return
this.Application.ActiveExplorer().Selection; }
}
// Called only the first time
private void ThisAddIn_Startup(object sender, System.EventArgs
e)
{
try
{
// Add VSTO Menus
CreateVSTOPopupMenus();
}
catch (Exception exp)
{
MessageBox.Show("Error: " + exp.ToString());
}
}
public void CreateVSTOPopupMenus()
{
Office.CommandBar currentBar =
this.Application.ActiveExplorer().CommandBars["Standard"];

// Add Popup Menus
CreateEmailIssuePopUp(); // Popup 1
CreateFavoritesMenu(); // Popup 2

}
private void CreateEmailIssuePopUp()
{
Office.CommandBar currentBar =
this.Application.ActiveExplorer().CommandBars["Standard"];

Office.CommandBarPopup c =
(Office.CommandBarPopup)currentBar.Controls.Add(Of fice.MsoControlType.msoControlPopup,
1, "", 1, true);
c.Caption = "TAC Net";
c.Visible = true;
c.Tag = "TAC Net";

PopulateEmailIssueListPopUp(c);
}
public void CreateFavoritesMenu()
{
// Get a reference to outlook's command bar
Office.CommandBar currentBar =
this.Application.ActiveExplorer().CommandBars["Standard"];
Office.CommandBarPopup favoritesMenu =
(Office.CommandBarPopup)currentBar.Controls.Add(Of fice.MsoControlType.msoControlPopup,
1, "", 1, true);
favoritesMenu.Caption = "Favorites";
favoritesMenu.Visible = true;
favoritesMenu.Tag = "Favorites";
PopulateEmailIssueListPopUp(favoritesMenu);
}
private void
PopulateEmailIssueListPopUp(Office.CommandBarPopup
emailIssueListPopUp)
{
Office.CommandBarControl button =
emailIssueListPopUp.Controls.Add(Office.MsoControl Type.msoControlButton,
System.Type.Missing, "dummy", missing, false);
button.Caption = "* dummy";
// Add event handler to save the email to the
corresponding document library
Office.CommandBarButton buttonControl = button as
Office.CommandBarButton;
//buttonControl.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(EmailIssueButton_Click);
buttonControl.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(Button1_Click);
}
private void
Button1_Click(Microsoft.Office.Core.CommandBarButt on Ctrl, ref bool
CancelDefault)
{
MessageBox.Show(Ctrl.Caption + ":" +
CancelDefault.ToString());
}
private void ThisAddIn_Shutdown(object sender,
System.EventArgs e)
{

}

#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  
Old April 20th 07, 02:18 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default VSTO Outlook 2003 - Issue with button event handlers

Anything you want kept alive has to be declared at the module level of the
class, not locally in some procedure. The garbage collector is eating your
button references. Declare your button objects at module level.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Soumitra" wrote in message
oups.com...
Hi,

I am developing a VSTO add-in for Outlook 2003 using VS. NET 2005 VSTO
template. I am adding two command buttons to Outlook's standard tool
bar. These buttons are hooked up to an event handler
(Button1_Click). When I start outlook I see the two buttons, however
for some reason only one button is hooked to the event handler. This
does not depend on the order in which the buttons are created. There
seems to be no patter to this. Sometimes event handler for both
buttons work. But usually the event handler for the button that is
clicked first works. To me it seems like Outlook disposes the second
button for some reason. I have pasted the code inside ThisAddIn.cs
below. In this code the two buttons are added to two separate Popup.
However, the result is same as directly adding the buttons to the
standard tool bar.

Please let me know if anyone has any thoughts on this.

Thanks,
Soumitra Mishra

namespace IssueEmailAddIn2003
{
public partial class ThisAddIn
{
private Microsoft.Office.Interop.Outlook.Selection
currentSelection;
public Microsoft.Office.Interop.Outlook.Selection
CurrentSelection
{
get { return
this.Application.ActiveExplorer().Selection; }
}
// Called only the first time
private void ThisAddIn_Startup(object sender, System.EventArgs
e)
{
try
{
// Add VSTO Menus
CreateVSTOPopupMenus();
}
catch (Exception exp)
{
MessageBox.Show("Error: " + exp.ToString());
}
}
public void CreateVSTOPopupMenus()
{
Office.CommandBar currentBar =
this.Application.ActiveExplorer().CommandBars["Standard"];

// Add Popup Menus
CreateEmailIssuePopUp(); // Popup 1
CreateFavoritesMenu(); // Popup 2

}
private void CreateEmailIssuePopUp()
{
Office.CommandBar currentBar =
this.Application.ActiveExplorer().CommandBars["Standard"];

Office.CommandBarPopup c =
(Office.CommandBarPopup)currentBar.Controls.Add(Of fice.MsoControlType.msoControlPopup,
1, "", 1, true);
c.Caption = "TAC Net";
c.Visible = true;
c.Tag = "TAC Net";

PopulateEmailIssueListPopUp(c);
}
public void CreateFavoritesMenu()
{
// Get a reference to outlook's command bar
Office.CommandBar currentBar =
this.Application.ActiveExplorer().CommandBars["Standard"];
Office.CommandBarPopup favoritesMenu =
(Office.CommandBarPopup)currentBar.Controls.Add(Of fice.MsoControlType.msoControlPopup,
1, "", 1, true);
favoritesMenu.Caption = "Favorites";
favoritesMenu.Visible = true;
favoritesMenu.Tag = "Favorites";
PopulateEmailIssueListPopUp(favoritesMenu);
}
private void
PopulateEmailIssueListPopUp(Office.CommandBarPopup
emailIssueListPopUp)
{
Office.CommandBarControl button =
emailIssueListPopUp.Controls.Add(Office.MsoControl Type.msoControlButton,
System.Type.Missing, "dummy", missing, false);
button.Caption = "* dummy";
// Add event handler to save the email to the
corresponding document library
Office.CommandBarButton buttonControl = button as
Office.CommandBarButton;
//buttonControl.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(EmailIssueButton_Click);
buttonControl.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(Button1_Click);
}
private void
Button1_Click(Microsoft.Office.Core.CommandBarButt on Ctrl, ref bool
CancelDefault)
{
MessageBox.Show(Ctrl.Caption + ":" +
CancelDefault.ToString());
}
private void ThisAddIn_Shutdown(object sender,
System.EventArgs e)
{

}

#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
}

}


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
outlook 2003 vsto Danny Kjærgaard Add-ins for Outlook 1 March 19th 07 01:23 PM
(VSTO SE) folder.Items.ItemAdd Event does not fire David Outlook and VBA 5 March 7th 07 08:41 PM
Outlook 2003, Designed Forms and button event handlers AIK Outlook - Using Forms 3 November 13th 06 01:25 PM
Outlook 2003 and VSTO questions Christie Add-ins for Outlook 0 November 3rd 06 07:19 AM
Outlook VSTO Appointment Item Delete Event lg Add-ins for Outlook 0 July 31st 06 10:35 AM


All times are GMT +1. The time now is 08:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.