1 Replies - 4125 Views - Last Post: 15 November 2008 - 05:43 AM Rate Topic: -----

#1 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

References in VB different from C#? Why?

Posted 15 November 2008 - 05:19 AM

Hello.
I'm trying to use Dim menuSet As reference Microsoft.Office.Interop.Visio.menuSets.get_ItemAtID()
This works fine in C#

In VB, it doesnt give me any error, but when i run, it tells me that Public member 'get_ItemAtID()' on Type MenuSetsClass not found.
When i browse the component, I cant find MANY THINGS under Microsoft.Office.Interop.Visio in VB that EXIST under Microsoft.Office.Interop.Visio in C#

Both are using the same Microsoft.Office.Interop.Visio.dll

I dnt get it... Wth? Any help please?

This post has been edited by Ameel: 15 November 2008 - 08:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: References in VB different from C#? Why?

#2 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: References in VB different from C#? Why?

Posted 15 November 2008 - 05:43 AM

Basically I was converting a C# code to VB.


Original Code as per Shashidhar:
using System;
using System.Runtime.InteropServices;
using Visio=Microsoft.Office.Interop.Visio;

#region NameSpace
namespace CustomMenus
{
	/// <summary>
	/// This class creates the custom menus and handles the click event 
	/// for the visio application.
	/// </summary>
	public class CustomMenu
	{
		#region private variables
		//to get all the Commandbars from the visio application
		//Ex:Menu Bar
		private Microsoft.Office.Core.CommandBars commandBars;
		//to get the Commandbar from the visio application
		//Ex:File Menu
		private Microsoft.Office.Core.CommandBar commandBar;
		//to get the CommandbarButton from the visio application
		//Ex:New Menu
		private Microsoft.Office.Core.CommandBarButton commandBarButton;
		//Holds the reference of visio application
		private Visio.Application visioApplication;
		
		#endregion

		#region Constructors
		public CustomMenu()
		{
			try
			{
				// Holding the visio application
				object visioObject = Marshal.GetActiveObject("Visio.Application");
				//converting object type to Visio type
				this.visioApplication = visioObject as Visio.Application;
			}
			catch(COMException exception)
			{
				throw exception;
			}
			catch(Exception exception)
			{
				throw exception;
			}
		}
		#endregion

		#region public methods

		/// <summary>
		/// Method to create custom menu 
		/// </summary>
		public void SetMenus()
		{
			try
			{
				if ( this.visioApplication != null )
				{
					if ( this.visioApplication.ActiveWindow != null )
					{
						//Get the built in menus to the UIObject
						Visio.UIObject uiObject = this.visioApplication.BuiltInMenus;
						//Get the menu sets of the visio application
						Visio.MenuSets menuSets = uiObject.MenuSets;
						//Get the item Id of the drawing object
						short itemId = (short)Visio.VisUIObjSets.visUIObjSetDrawing;
						//Get the menu set of drawing object
						Visio.MenuSet menuSet = menuSets.get_ItemAtID(itemId);
						//Get the menus from menu set
						Visio.Menus menus = menuSet.Menus;
						//Add the menu at a position
						Visio.Menu menu = menus.AddAt(7);
						//Set the menu caption 
						menu.Caption = "&Sample";
						//Set the menu items to the menu
						Visio.MenuItems menuItems = menu.MenuItems;
						//Add the menu Item to the menu
						Visio.MenuItem item = menuItems.Add();
						//Set the menu item caption 
						item.Caption = "&Test";
						//Set the custom menu to the active document
						this.visioApplication.Activewindow.document.SetCustomMenus(uiObject);
						//Get the current commandbars of the visio application
						commandBars=(Microsoft.Office.Core.CommandBars) this.visioApplication.CommandBars;
						//Get the Menu Bar which is located at 3 in CommandBars
						commandBar=commandBars[3];
						//Get the commandBar button which is located at 1 position of Sample menu
						commandBarButton = commandBar.Controls[8].get_accChild(1) as Microsoft.Office.Core.CommandBarButton;//commandBar.Controls[8].Control as Microsoft.Office.Core.CommandBarButton;
						//Set the style of the commandBar button
						commandBarButton.Style=Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;
						//Event Handler to execute the defined functionality
						commandBarButton.Click +=new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(OnCommandBarButtonclick);
					}
				}
			}
			catch(COMException exception)
			{
				throw exception;
			}
			catch(Exception exception)
			{
				throw exception;
			}
		}

		/// <summary>
		/// Method to clear custom menu 
		/// </summary>
		public void ClearMenu()
		{
			try
			{
				//check for the reference of active window 
				if ( this.visioApplication.ActiveWindow != null )
				{
					//clear the custom menu
					this.visioApplication.Activewindow.document.ClearCustomMenus();
				}
			}
			catch(COMException exception)
			{
				throw exception;
			}
			catch(Exception exception)
			{
				throw exception;
			}
		}

		#endregion

		#region event handlers

		/// <summary>
		/// Event to handle click event of the menu item
		/// </summary>
		/// <param name="Ctrl">Holds CommandBar Button</param>
		/// <param name="CancelDefault">Holds refernced Boolean</param>
		private void OnCommandBarButtonclick(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
		{
			//Here comes the statements....

			Console.WriteLine("Menu selected");
			
		}
		#endregion
	}
}
#endregion



Converted Code:
Imports System
Imports System.Runtime.InteropServices
Imports Visio = Microsoft.Office.Interop.Visio
Imports visio2 = Microsoft.Office.Interop.Visio.MenuSets


''' <summary>
''' This class creates the custom menus and handles the click event 
''' for the visio application.
''' </summary>
Public Class CustomMenu

	'to get all the Commandbars from the visio application
	'Ex:Menu Bar
	Private commandBars As Microsoft.Office.Core.CommandBars
	'to get the Commandbar from the visio application
	'Ex:File Menu
	Private commandBar As Microsoft.Office.Core.CommandBar
	'to get the CommandbarButton from the visio application
	'Ex:New Menu
	Private commandBarButton As Microsoft.Office.Core.CommandBarButton
	'Holds the reference of visio application
	Private visioApplication As Visio.Application


	Public Sub New()
		Try
			' Holding the visio application
			Dim visioObject As Object = Marshal.GetActiveObject("Visio.Application")
			'converting object type to Visio type
			Me.visioApplication = TryCast(visioObject, Visio.Application)
		Catch exception As COMException
			Throw exception
		Catch exception As Exception
			Throw exception
		End Try
	End Sub


	''' <summary>
	''' Method to create custom menu 
	''' </summary>
	Public Sub SetMenus()
		Try

			If Me.visioApplication IsNot Nothing Then

				If Me.visioApplication.ActiveWindow IsNot Nothing Then
					'Get the built in menus to the UIObject
					Dim uiObject As Visio.UIObject = Me.visioApplication.BuiltInMenus
					'Get the menu sets of the visio application
					Dim menuSets As Visio.MenuSets = uiObject.MenuSets
					'Get the item Id of the drawing object
					Dim itemId As Short = CShort(Visio.VisUIObjSets.visUIObjSetDrawing)
					'Get the menu set of drawing object
					Dim menuSet As Visio.MenuSet = menuSets.get_ItemAtID(itemId)
					'Get the menus from menu set
					Dim menus As Visio.Menus = menuSet.Menus
					'Add the menu at a position
					Dim menu As Visio.Menu = menus.AddAt(7)
					'Set the menu caption 
					menu.Caption = "&Sample"
					'Set the menu items to the menu
					Dim menuItems As Visio.MenuItems = menu.MenuItems
					'Add the menu Item to the menu
					Dim item As Visio.MenuItem = menuItems.Add()
					'Set the menu item caption 
					item.Caption = "&Test"
					'Set the custom menu to the active document
					Me.visioApplication.Activewindow.document.SetCustomMenus(uiObject)
					'Get the current commandbars of the visio application
					commandBars = DirectCast(Me.visioApplication.CommandBars, Microsoft.Office.Core.CommandBars)
					'Get the Menu Bar which is located at 3 in CommandBars
					commandBar = commandBars(3)
					'Get the commandBar button which is located at 1 position of Sample menu
					commandBarButton = TryCast(commandBar.Controls(8).get_accChild(1), Microsoft.Office.Core.CommandBarButton)
					'commandBar.Controls[8].Control as Microsoft.Office.Core.CommandBarButton;
					'Set the style of the commandBar button
					commandBarButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption
					'Event Handler to execute the defined functionality
					AddHandler commandBarButton.Click, AddressOf OnCommandBarButtonclick
				End If
			End If
		Catch exception As COMException
			Throw exception
		Catch exception As Exception
			Throw exception
		End Try
	End Sub

	''' <summary>
	''' Method to clear custom menu 
	''' </summary>
	Public Sub ClearMenu()
		Try
			'check for the reference of active window 
			If Me.visioApplication.ActiveWindow IsNot Nothing Then
				'clear the custom menu
				Me.visioApplication.Activewindow.document.ClearCustomMenus()
			End If
		Catch exception As COMException
			Throw exception
		Catch exception As Exception
			Throw exception
		End Try
	End Sub



	''' <summary>
	''' Event to handle click event of the menu item
	''' </summary>
	''' <param name="Ctrl">Holds CommandBar Button</param>
	''' <param name="CancelDefault">Holds refernced Boolean</param>
	Private Sub OnCommandBarButtonclick(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
		'Here comes the statements....

		Console.WriteLine("Menu selected")
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1