S
Scott English
I am creating an Outlook Add-in in C#. I want to programmatically manipulate an Outlook form. I am using the PIAs for Office XP.
The ModifiedFormPages property of an Inspector returns a Pages collection. The Add method and Items property return an object of type Object. All the example code I find (which is all for VB or VBScript) says that this object has a Controls property on it that can be used to access the controls on the page. If I use VB.NET, I can access the Controls property (using VB's late binding) and get a Forms.Controls collection back. The "page" object, however, is not a Forms.Page object. In fact, I can't figure out the object's type. The GetType().FullName reports "__ComObject".
C#, however, doesn't let me call the Controls property since it doesn't allow the late-binding that VB.NET does.
The following event is wired up to the NewInspector event of the ActiveInspector
private void Inspectors_NewInspector(Outlook.Inspector inspector)
{
Outlook.Pages pages = (Outlook.Pages)inspector.ModifiedFormPages;
object page = pages.Add("Test");
Type pageType = page.GetType();
Debug.WriteLine(pageType.FullName); // Prints "__ComObject"
Forms.Controls controls = (Forms.Controls)page.Controls; // Won't compile. How do I make this call?
}
The following VB.NET code works.
Private Sub Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector) Handles Inspectors.NewInspector
Dim page As Object = Inspector.ModifiedFormPages.Add("Test")
If TypeOf page Is Forms.Page Then Debug.WriteLine("Page!") ' Nothing Prints
If TypeOf page.Controls Is Forms.Controls Then Debug.WriteLine("Controls!") ' Prints "Controls!" No problem calling the Controls method using VB's late binding.
Dim TextBox1 As Forms.TextBox = page.Controls.Add("Forms.TextBox.1", "TextBox1", True)
Inspector.ShowFormPage("Test")
End Sub
The ModifiedFormPages property of an Inspector returns a Pages collection. The Add method and Items property return an object of type Object. All the example code I find (which is all for VB or VBScript) says that this object has a Controls property on it that can be used to access the controls on the page. If I use VB.NET, I can access the Controls property (using VB's late binding) and get a Forms.Controls collection back. The "page" object, however, is not a Forms.Page object. In fact, I can't figure out the object's type. The GetType().FullName reports "__ComObject".
C#, however, doesn't let me call the Controls property since it doesn't allow the late-binding that VB.NET does.
The following event is wired up to the NewInspector event of the ActiveInspector
private void Inspectors_NewInspector(Outlook.Inspector inspector)
{
Outlook.Pages pages = (Outlook.Pages)inspector.ModifiedFormPages;
object page = pages.Add("Test");
Type pageType = page.GetType();
Debug.WriteLine(pageType.FullName); // Prints "__ComObject"
Forms.Controls controls = (Forms.Controls)page.Controls; // Won't compile. How do I make this call?
}
The following VB.NET code works.
Private Sub Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector) Handles Inspectors.NewInspector
Dim page As Object = Inspector.ModifiedFormPages.Add("Test")
If TypeOf page Is Forms.Page Then Debug.WriteLine("Page!") ' Nothing Prints
If TypeOf page.Controls Is Forms.Controls Then Debug.WriteLine("Controls!") ' Prints "Controls!" No problem calling the Controls method using VB's late binding.
Dim TextBox1 As Forms.TextBox = page.Controls.Add("Forms.TextBox.1", "TextBox1", True)
Inspector.ShowFormPage("Test")
End Sub