About the Configure a command for a specific locale Sample
[C#]
CultureTool.cs
using System;
using System.Resources;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Globalization;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using System.Windows.Forms;
namespace VBCSharpCultureSample
{
/// <summary>
/// Summary description for Tool1.
/// </summary>
[Guid("490b461a-f596-4177-9b5d-411cbb13a684")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("VBCSharpCultureSample.CultureTool")]
public sealed class CultureTool : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
private IHookHelper m_pHookHelper;
public CultureTool()
{
ResourceManager rm = new ResourceManager("VBCSharpCultureSample.Resources", Assembly.GetExecutingAssembly());
base.m_bitmap = (System.Drawing.Bitmap)rm.GetObject("ToolImage");
base.m_message = (string)rm.GetString("ToolMessage");
base.m_toolTip = (string)rm.GetString("ToolToolTip");
base.m_caption = (string)rm.GetString("ToolCaption");
base.m_category = "CustomCommands";
base.m_name = "CustomCommands_CultureTool";
}
#region Overriden Class Methods
/// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (m_pHookHelper == null)
m_pHookHelper = new HookHelperClass();
m_pHookHelper.Hook = hook;
// TODO: Add Tool1.OnCreate implementation
}
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add Tool1.OnClick implementation
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
//With this tool the user may place the current Date and Time onto the Page Layout
//using the Timestamp format defined by the UI Culture of the current thread
//Get the active view
IActiveView pActiveView;
pActiveView = m_pHookHelper.ActiveView;
//Create a new text element
ITextElement pTextElement = new TextElementClass();
//Create a text symbol
ESRI.ArcGIS.Display.ITextSymbol pTextSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();
pTextSymbol.Size = 10;
//Create a page point
IPoint pPoint;
pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
//Get the FullDateTimePattern from the CurrentUICulture of the thread
string pDateTimePattern;
pDateTimePattern = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.FullDateTimePattern.ToString();
//Set the text element properties
pTextElement.Symbol = pTextSymbol;
pTextElement.Text = System.DateTime.Now.ToString(pDateTimePattern);
//QI for IElement
IElement pElement;
pElement = (IElement)pTextElement;
//Set the elements geometry
pElement.Geometry = pPoint;
//Add the element to the graphics container
pActiveView.GraphicsContainer.AddElement(pElement, 0);
//Refresh the graphics
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseMove implementation
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseUp implementation
}
#endregion
}
}
[Visual Basic .NET]
CultureTool.vb
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.ADF.BaseClasses
Imports System.Globalization
<ComClass(CultureTool.ClassId, CultureTool.InterfaceId, CultureTool.EventsId)> _
Public NotInheritable Class CultureTool
Inherits BaseTool
'The HookHelper object that deals with the hook passed to the OnCreate event
Private m_pHookHelper As New HookHelperClass
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "2e2ab7c0-a7a3-4f40-9b58-c67f96c8f463"
Public Const InterfaceId As String = "c55088e2-af75-42e3-8c8d-2ca28f51f86d"
Public Const EventsId As String = "ce02de9c-98e5-4bb6-92c8-2a6f0ed6ce3c"
#End Region
#Region "Component Category Registration"
<ComRegisterFunction(), ComVisible(False)> _
Public Shared Sub RegisterFunction(ByVal sKey As String)
Dim fullKey As String = sKey.Remove(0, 18) & "\Implemented Categories"
Dim regKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fullKey, True)
If Not (regKey Is Nothing) Then
regKey.CreateSubKey("{B284D891-22EE-4F12-A0A9-B1DDED9197F4}")
End If
End Sub
<ComUnregisterFunction(), ComVisible(False)> _
Public Shared Sub UnregisterFunction(ByVal sKey As String)
Dim fullKey As String = sKey.Remove(0, 18) & "\Implemented Categories"
Dim regKey As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fullKey, True)
If Not (regKey Is Nothing) Then
regKey.DeleteSubKey("{B284D891-22EE-4F12-A0A9-B1DDED9197F4}")
End If
End Sub
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
'The BitMap, Caption, Message and ToolTip are set from strings and images
'stored in the Resource File. The ResourceManager acquires the appropriate
'Resource file according to the UI Culture of the current thread
Dim pResourceManager As New System.Resources.ResourceManager("VBDotNetCultureSample.Resources", Me.GetType().Assembly)
Dim pResource_bitmap As System.Drawing.Bitmap
Dim pResource_str As String
'Set the tool properties
pResource_bitmap = CType(pResourceManager.GetObject("ToolImage"), System.Drawing.Bitmap)
MyBase.m_bitmap = New System.Drawing.Bitmap(pResource_bitmap)
pResource_str = CType(pResourceManager.GetObject("ToolCaption"), String)
MyBase.m_caption = pResource_str
pResource_str = CType(pResourceManager.GetObject("ToolMessage"), String)
MyBase.m_message = pResource_str
pResource_str = CType(pResourceManager.GetObject("ToolToolTip"), String)
MyBase.m_toolTip = pResource_str
MyBase.m_category = "CustomCommands"
MyBase.m_name = "CustomCommands_CultureTool"
End Sub
Public Overrides Sub OnCreate(ByVal hook As Object)
m_pHookHelper.Hook = hook
End Sub
Public Overrides ReadOnly Property Enabled() As Boolean
Get
'Set the enabled property
If Not m_pHookHelper.ActiveView Is Nothing Then
Return True
Else
Return False
End If
End Get
End Property
Public Overrides Sub OnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Integer, ByVal Y As Integer)
'With this tool the user may place the current Date and Time onto the Page Layout
'using the Timestamp format defined by the UI Culture of the current thread
'Get the active view
Dim pActiveView As IActiveView
pActiveView = m_pHookHelper.ActiveView
'Create a new text element
Dim pTextElement As ITextElement
pTextElement = New TextElement
'Create a text symbol
Dim pTextSymbol As ITextSymbol
pTextSymbol = New TextSymbol
pTextSymbol.Size = 10
'Create a page point
Dim pPoint As IPoint
pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y)
'Get the FullDateTimePattern from the CurrentUICulture of the thread
Dim pDateTimePattern As String
pDateTimePattern = System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat.FullDateTimePattern.ToString()
'Set the text element properties
pTextElement.Symbol = pTextSymbol
pTextElement.Text = System.DateTime.Now.ToString(pDateTimePattern)
'QI for IElement
Dim pElement As IElement
pElement = pTextElement
'Set the elements geometry
pElement.Geometry = pPoint
'Add the element to the graphics container
pActiveView.GraphicsContainer.AddElement(pTextElement, 0)
'Refresh the graphics
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)
End Sub
End Class