/// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
              {
            IMapControl4 mapControl = null;

            if (m_pHookHelper.Hook is IMapControl4)
              mapControl = (IMapControl4)m_pHookHelper.Hook;
            else if (m_pHookHelper.Hook is IToolbarControl2)
            {
              IToolbarControl2 toolbarControl = (IToolbarControl2)m_pHookHelper.Hook;
              mapControl = (IMapControl4)toolbarControl.Buddy;
            }

            if (null == mapControl.CustomProperty || !(mapControl.CustomProperty is IFeatureLayer))
              return;

            IFeatureLayer featureLayer = (IFeatureLayer)mapControl.CustomProperty;

            //Launch the layer's properties
            Type typ;
            object obj;
            Guid[] g;

            // METHOD 1: Instantiating a COM object and displaying its property pages
            // ONLY WORKS ON TRUE COM OBJECTS!  .NET objects that have rolled their own
            // ISpecifyPropertyPages implementation will error out when you try to cast
            // the instantiated object to your own ISpecifyPropertyPages implementation.

            // Get the typeinfo for the ActiveX common dialog control
            typ = Type.GetTypeFromProgID("MSComDlg.CommonDialog");

            // Create an instance of the control.  We pass it to the property frame function
            // so the property pages have an object from which to get current settings and apply
            // new settings.
            obj = Activator.CreateInstance(typ);
            // This handy function calls IPersistStreamInit->New on COM objects to initialize them
            ActiveXMessageFormatter.InitStreamedObject(obj);

            // Get the property pages for the control using the direct CAUUID method
            // This only works for true COM objects and I demonstrate it here only
            // to show how it is done.  Use the static method
            // PropertyPage.GetPagesForType() method for real-world use.
            ISpecifyPropertyPages pag = (ISpecifyPropertyPages)obj;
            CAUUID cau = new CAUUID(0);
            pag.GetPages(ref cau);
            g = cau.GetPages();

            // Instantiating a .NET object and displaying its property pages
            // WORKS ON ALL OBJECTS, .NET or COM

            // Create an instance of the .NET control, MyUserControl
            typ = Type.GetTypeFromProgID("SymbolSelector.PropertySheet");

            // Retrieve the pages for the control
            g = PropertyPage.GetPagesForType(typ);

            // Create an instance of the control that we can give to the property pages
            obj = Activator.CreateInstance(typ);

            ((SymbolSelector.PropertySheet)obj).OnFeatureLayerRendererChanged += new FeatureLayerRendererChanged(OnFeatureLayerRendererChanged);

            //add the yahoo layer to the property-sheet control
            ((SymbolSelector.PropertySheet)obj).FeatureLayer = featureLayer;

            // Display the OLE Property page for the control
            object[] items = new object[] { obj };

            PropertyPage.CreatePropertyFrame(IntPtr.Zero, 500, 500, "FeatureLayer Symbology", items, g);
              }
              catch (Exception ex)
              {
            System.Diagnostics.Trace.WriteLine(ex.Message);
              }
        }
    /// <summary>
    /// Occurs when this command is clicked
    /// </summary>
    public override void OnClick()
    {
      try
      {
        //search for the weatherLayer first
        ILayer layer = null;
        RSSWeatherLayerClass RSSLayer = null;

        if (m_pHookHelper.FocusMap.LayerCount == 0)
          return;

        IEnumLayer layers = m_pHookHelper.FocusMap.get_Layers(null, false);
        layers.Reset();
        layer = layers.Next();
        while (layer != null)
        {
          if (layer is RSSWeatherLayerClass)
          {
            RSSLayer = (RSSWeatherLayerClass)layer;
            break;
          }
          layer = layers.Next();
        }

        //In case that the weather layer wasn't found,just return
        if (null == RSSLayer)
          return;


        //Launch the layer's properties
        Type typ;
        object obj;
        Guid[] g;

        // METHOD 1: Instantiating a COM object and displaying its property pages
        // ONLY WORKS ON TRUE COM OBJECTS!  .NET objects that have rolled their own
        // ISpecifyPropertyPages implementation will error out when you try to cast
        // the instantiated object to your own ISpecifyPropertyPages implementation.

        // Get the typeinfo for the ActiveX common dialog control
        typ = Type.GetTypeFromProgID("MSComDlg.CommonDialog");

        // Create an instance of the control.  We pass it to the property frame function
        // so the property pages have an object from which to get current settings and apply
        // new settings.
        obj = Activator.CreateInstance(typ);
        // This handy function calls IPersistStreamInit->New on COM objects to initialize them
        ActiveXMessageFormatter.InitStreamedObject(obj);

        // Get the property pages for the control using the direct CAUUID method
        // This only works for true COM objects and I demonstrate it here only
        // to show how it is done.  Use the static method
        // PropertyPage.GetPagesForType() method for real-world use.
        ISpecifyPropertyPages pag = (ISpecifyPropertyPages)obj;
        CAUUID cau = new CAUUID(0);
        pag.GetPages(ref cau);
        g = cau.GetPages();

        // Instantiating a .NET object and displaying its property pages
        // WORKS ON ALL OBJECTS, .NET or COM    

        // Create an instance of the .NET control, MyUserControl
        typ = Type.GetTypeFromProgID("RSSWeatherLayer.PropertySheet");

        // Retrieve the pages for the control
        g = PropertyPage.GetPagesForType(typ);

        // Create an instance of the control that we can give to the property pages
        obj = Activator.CreateInstance(typ);

        //add the RSS layer to the property-sheet control
        ((PropertySheet)obj).RSSWatherLayer = RSSLayer;

        // Display the OLE Property page for the control
        object[] items = new object[] { obj };

        PropertyPage.CreatePropertyFrame(IntPtr.Zero, 500, 500, "RSS Layer properties", items, g);
      }
      catch (Exception ex)
      {
        System.Diagnostics.Trace.WriteLine(ex.Message);
      }
    }
Exemple #3
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                //search for the weatherLayer first
                ILayer layer = null;
                RSSWeatherLayerClass RSSLayer = null;

                if (m_pHookHelper.FocusMap.LayerCount == 0)
                {
                    return;
                }

                IEnumLayer layers = m_pHookHelper.FocusMap.get_Layers(null, false);
                layers.Reset();
                layer = layers.Next();
                while (layer != null)
                {
                    if (layer is RSSWeatherLayerClass)
                    {
                        RSSLayer = (RSSWeatherLayerClass)layer;
                        break;
                    }
                    layer = layers.Next();
                }

                //In case that the weather layer wasn't found,just return
                if (null == RSSLayer)
                {
                    return;
                }


                //Launch the layer's properties
                Type   typ;
                object obj;
                Guid[] g;

                // METHOD 1: Instantiating a COM object and displaying its property pages
                // ONLY WORKS ON TRUE COM OBJECTS!  .NET objects that have rolled their own
                // ISpecifyPropertyPages implementation will error out when you try to cast
                // the instantiated object to your own ISpecifyPropertyPages implementation.

                // Get the typeinfo for the ActiveX common dialog control
                typ = Type.GetTypeFromProgID("MSComDlg.CommonDialog");

                // Create an instance of the control.  We pass it to the property frame function
                // so the property pages have an object from which to get current settings and apply
                // new settings.
                obj = Activator.CreateInstance(typ);
                // This handy function calls IPersistStreamInit->New on COM objects to initialize them
                ActiveXMessageFormatter.InitStreamedObject(obj);

                // Get the property pages for the control using the direct CAUUID method
                // This only works for true COM objects and I demonstrate it here only
                // to show how it is done.  Use the static method
                // PropertyPage.GetPagesForType() method for real-world use.
                ISpecifyPropertyPages pag = (ISpecifyPropertyPages)obj;
                CAUUID cau = new CAUUID(0);
                pag.GetPages(ref cau);
                g = cau.GetPages();

                // Instantiating a .NET object and displaying its property pages
                // WORKS ON ALL OBJECTS, .NET or COM

                // Create an instance of the .NET control, MyUserControl
                typ = Type.GetTypeFromProgID("RSSWeatherLayer.PropertySheet");

                // Retrieve the pages for the control
                g = PropertyPage.GetPagesForType(typ);

                // Create an instance of the control that we can give to the property pages
                obj = Activator.CreateInstance(typ);

                //add the RSS layer to the property-sheet control
                ((PropertySheet)obj).RSSWatherLayer = RSSLayer;

                // Display the OLE Property page for the control
                object[] items = new object[] { obj };

                PropertyPage.CreatePropertyFrame(IntPtr.Zero, 500, 500, "RSS Layer properties", items, g);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }