Show all posts.
A long run - but never finished :) - project that I'm doing is a rule framework plugin for Outlook - FolderRules.NET - and as Orcas has some promising new features on VSTO integration I decided to convert my plugin to .NET 3.5.
The first we can notice that opening the New Project dialog we choose from a new suite of Office 2007 project templates - all based on the .NET framework 3.5:
 .
The source code that is generated by this wizard is fairly straightforward and we simply just can write our initialization code to the ThisAddin_Startup method.
In this example I'm telling Outlook that I need a new Option Page on the Tools->Options dialog and that I need a new menu item on the context menu that appears on each folder:
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
this.Application.OptionsPagesAdd += pages =>
pages.Add(new UserControl1(), "Folder Rules");
this.Application.FolderContextMenuDisplay +=
delegate(Office.CommandBar commandBar, Outlook.MAPIFolder folder)
{
CommandBarButton newButton = commandBar.Controls.Add(
MsoControlType.msoControlButton,
missing, missing, missing, missing) as CommandBarButton;
newButton.Caption = "Folder Rules";
newButton.FaceId = 473;
newButton.Style = MsoButtonStyle.msoButtonIconAndCaption;
newButton.Click += delegate(CommandBarButton control, ref bool cancelDefault)
{
MessageBox.Show("Test2");
};
};
|
As you can see the code instanciates a new UserControl1 class - this will be added on a new tab page on the Options dialog.
However it seems that creating a simple WPF control and exposing it to COM is not possible because the System.Windows.UserControl class is not ComVisible - so the trick here what we should do to have a XAML enabled control in the Options dialog is to use an ElementHost on our Windows Forms control which in turn will host a XAML enabled control.
Also an other thing we should do is to make our control to look like Outlook's control; so for this we should paint our control's background using the VisualStyleRenderer class like in the following code example:
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
VisualStyleRenderer renderer;
VisualStyleElement element = VisualStyleElement.Tab.Body.Normal;
public UserControl1()
{
InitializeComponent();
if (Application.RenderWithVisualStyles &&
VisualStyleRenderer.IsElementDefined(element))
{
renderer = new VisualStyleRenderer(element);
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (renderer != null)
{
renderer.DrawBackground(e.Graphics, this.ClientRectangle);
}
base.OnPaint(e);
}
|
Enjoy :)
|