StyleGalleryItem Symbol

807
1
08-24-2011 02:53 AM
ToniMc
by
New Contributor
How can i put(draw) symbol from SymbolControl on map? When selected item symbol from SymbolControl, and then click on map control, selected item from symbol control didnt show.

code:
...
   private IStyleGalleryItem m_StyleGalleryItem;

   private void MainForm_Load(object sender, EventArgs e){

      string sInstall = ESRI.ArcGIS.RuntimeManager.ActiveRuntime.Path;
      axSymbologyControl1.LoadStyleFile(sInstall + "\\Styles\\ESRI.ServerStyle");
      axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassMarkerSymbol;
   }

   private void axSymbologyControl1_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e){

     m_StyleGalleryItem = (IStyleGalleryItem)e.styleGalleryItem;

   }

   private void axMapControl1_OnMouseDown(object sender,             IMapControlEvents2_OnMouseDownEvent e){

     IPoint point = new PointClass();
     point.PutCoords(e.x, e.y);
   
     IElement element = (IElement)m_StyleGalleryItem;
     element.Geometry = point;
    
     axMapControl1.ActiveView.GraphicsContainer.AddElement(element, 0);
     axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriGraphics, m_StyleGalleryItem, null);

   }
...

How can i cast m_StyleGalleryItem to IElement?

Any advice! Thanks
0 Kudos
1 Reply
ToniMc
by
New Contributor
I have solved this problem, and it works fine.
Just have to expand axMapControl1_OnMouseDown event :

private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e){

    IElement element = new MarkerElementClass();
  
    IPoint point = new PointClass();
    point.PutCoords(e.mapX, e.mapY);

    element.Geometry = (IGeometry)point;

    IMarkerElement markerElement = (IMarkerElement)element;

    IMarkerSymbol markerSymbol = (IMarkerSymbol)m_StyleGalleryItem.Item;

    markerElement.Symbol = markerSymbol;   

   axMapControl1.ActiveView.GraphicsContainer.AddElement(element, 0);
   axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriGraphics, null, null);


}
0 Kudos