Hi,
Please find the code...working
public override void OnClick()
{
try
{
IMxDocument pMxDoc = m_application.Document as IMxDocument;
IActiveView pActiveView;
pActiveView = pMxDoc.PageLayout as IActiveView;
IGraphicsContainer pGraphicsContainer;
IMapFrame pMapFrame;
pGraphicsContainer = pMxDoc.PageLayout as IGraphicsContainer;
pMapFrame = pGraphicsContainer.FindFrame(pMxDoc.FocusMap) as IMapFrame;
IMapSurroundFrame pMapSurroundFrame;
UID pUID = new UIDClass();
IElement pElement;
pUID.Value = "esriCarto.Legend";
pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);
pMapSurroundFrame.MapSurround.Name = "Legend";
pElement = pMapSurroundFrame as IElement;
IElement pMainMapElement;
IEnvelope pMainEnv;
pMainMapElement = pMapFrame as IElement;
pMainEnv = pMainMapElement.Geometry.Envelope;
IEnvelope pEnv = new EnvelopeClass();
pEnv.PutCoords(pMainEnv.XMax + 1.5, pMainEnv.YMin + 1.5, pMainEnv.XMax - 1.5, pMainEnv.YMax - 1.5);
pElement.Geometry = pEnv;
pElement.Activate(pActiveView.ScreenDisplay);
pGraphicsContainer.AddElement(pElement, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
pActiveView.Refresh();
}
catch (Exception exe) { }
}
Thanks and Regards,
Venkat