Hi,
Please find the code....
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;
namespace CountPoints
{
/// <summary>
/// Summary description for InsertPic.
/// </summary>
[Guid("b311d914-e999-4014-8bcb-2cef2da34b71")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("CountPoints.InsertPic")]
public sealed class InsertPic : BaseCommand
{
#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);
MxCommands.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);
MxCommands.Unregister(regKey);
}
#endregion
#endregion
private IApplication m_application;
public InsertPic()
{
//
// TODO: Define values for the public properties
//
base.m_category = "PageLayout"; //localizable text
base.m_caption = "Insert Pic"; //localizable text
base.m_message = "Insert Picture into Pagelayout"; //localizable text
base.m_toolTip = "Insert Picture into Pagelayout"; //localizable text
base.m_name = "Insert_pic"; //unique id, non-localizable (e.g. "MyCategory_ArcMapCommand")
try
{
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#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 (hook == null)
return;
m_application = hook as IApplication;
//Disable if it is not ArcMap
if (hook is IMxApplication)
base.m_enabled = true;
else
base.m_enabled = false;
// TODO: Add other initialization code
}
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add InsertPic.OnClick implementation
IMxDocument pMxDoc = m_application.Document as IMxDocument;
ESRI.ArcGIS.Carto.IPictureElement pPictureElement;
pPictureElement = new ESRI.ArcGIS.Carto.JpgPictureElementClass();
pPictureElement.ImportPictureFromFile(@"D:\PROJECTS\MyProject\Images\Excel2.jpg");
ESRI.ArcGIS.Geometry.IEnvelope pEnv = new ESRI.ArcGIS.Geometry.EnvelopeClass();
pEnv.PutCoords(1, 1, 5, 5);
ESRI.ArcGIS.Carto.IElement pElement;
pElement = pPictureElement as ESRI.ArcGIS.Carto.IElement;
pElement.Geometry = pEnv;
ESRI.ArcGIS.Carto.IGraphicsContainer pGraphicContainer;
pGraphicContainer = pMxDoc.PageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;
pGraphicContainer.AddElement(pElement, 0);
ESRI.ArcGIS.Carto.IActiveView pActiveView;
pActiveView = pGraphicContainer as ESRI.ArcGIS.Carto.IActiveView;
pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGraphics, pElement, pEnv);
}
#endregion
}
}
I hope this helps you...
Thanks and Regards,
Venkat