- bits & pieces about software development HostingAbc Logo
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 :)
add linkThe last comments:lucifer says:oh, i see now :D lucifer says:"If the LINQ runtime just thrown an exception similar to this one to your face". which one? :)apco says:1) Define the original issue. 2) The sorted list is sorted on value and there is not a key! 3) dark green text with black background: not too easy to read.moszidev says:Actually I've made these 2 forms with Expression Blend. I'm not sure if the extensive designing capabilities will be included in the VS designer ...Venemo says:I've just tried out Visual Studio 2008 Express, and it doesn't have the functionality to rotate the controls, but when I copied your source code, it recognised it. Anyway, it seems very similar to VS 2005, and only has a few improvements in its interBéla says:At long last! I'm looking forward to it! Keep it up! and so on ;)
Copyright (C) 2007, Molnar Szilveszter m@il me