public static bool NeedsComponentEditor(object obj)
 {
     if (obj is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
     {
         Guid empty = Guid.Empty;
         if ((((System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)obj).MapPropertyToPage(-1, out empty) == 0) && !empty.Equals(Guid.Empty))
         {
             return(true);
         }
     }
     if (obj is System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)
     {
         try
         {
             System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
             try
             {
                 ((System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)obj).GetPages(pPages);
                 if (pPages.cElems > 0)
                 {
                     return(true);
                 }
             }
             finally
             {
                 if (pPages.pElems != IntPtr.Zero)
                 {
                     Marshal.FreeCoTaskMem(pPages.pElems);
                 }
             }
         }
         catch
         {
         }
     }
     return(false);
 }
 public void ShowPropertyPages(Control control)
 {
     try
     {
         if (this.CanShowPropertyPages())
         {
             System.Windows.Forms.NativeMethods.ISpecifyPropertyPages ocx = (System.Windows.Forms.NativeMethods.ISpecifyPropertyPages) this.GetOcx();
             System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
             try
             {
                 ocx.GetPages(pPages);
                 if (pPages.cElems <= 0)
                 {
                     return;
                 }
             }
             catch
             {
                 return;
             }
             IDesignerHost service = null;
             if (this.Site != null)
             {
                 service = (IDesignerHost) this.Site.GetService(typeof(IDesignerHost));
             }
             DesignerTransaction transaction = null;
             try
             {
                 if (service != null)
                 {
                     transaction = service.CreateTransaction(System.Windows.Forms.SR.GetString("AXEditProperties"));
                 }
                 string caption = null;
                 object pobjs = this.GetOcx();
                 IntPtr handle = (this.ContainingControl == null) ? IntPtr.Zero : this.ContainingControl.Handle;
                 System.Windows.Forms.SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(this, handle), 0, 0, caption, 1, ref pobjs, pPages.cElems, new HandleRef(null, pPages.pElems), Application.CurrentCulture.LCID, 0, IntPtr.Zero);
             }
             finally
             {
                 if (this.oleSite != null)
                 {
                     ((System.Windows.Forms.UnsafeNativeMethods.IPropertyNotifySink) this.oleSite).OnChanged(-1);
                 }
                 if (transaction != null)
                 {
                     transaction.Commit();
                 }
                 if (pPages.pElems != IntPtr.Zero)
                 {
                     Marshal.FreeCoTaskMem(pPages.pElems);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
 public bool HasPropertyPages()
 {
     if (this.CanShowPropertyPages())
     {
         System.Windows.Forms.NativeMethods.ISpecifyPropertyPages ocx = (System.Windows.Forms.NativeMethods.ISpecifyPropertyPages) this.GetOcx();
         try
         {
             System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
             try
             {
                 ocx.GetPages(pPages);
                 if (pPages.cElems > 0)
                 {
                     return true;
                 }
             }
             finally
             {
                 if (pPages.pElems != IntPtr.Zero)
                 {
                     Marshal.FreeCoTaskMem(pPages.pElems);
                 }
             }
         }
         catch
         {
         }
     }
     return false;
 }
        public override bool EditComponent(ITypeDescriptorContext context, object obj, IWin32Window parent)
        {
            IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;

            if (obj is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
            {
                Guid empty = Guid.Empty;
                if ((((System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)obj).MapPropertyToPage(-1, out empty) == 0) && !empty.Equals(Guid.Empty))
                {
                    object pobjs  = obj;
                    Guid[] pClsid = new Guid[] { empty };
                    SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref pobjs, 1, pClsid, Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                    return(true);
                }
            }
            if (obj is System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)
            {
                Exception exception;
                bool      flag = false;
                try
                {
                    System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
                    try
                    {
                        ((System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)obj).GetPages(pPages);
                        if (pPages.cElems <= 0)
                        {
                            return(false);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                    try
                    {
                        object obj3 = obj;
                        SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref obj3, pPages.cElems, new HandleRef(pPages, pPages.pElems), Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                        return(true);
                    }
                    finally
                    {
                        if (pPages.pElems != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(pPages.pElems);
                        }
                    }
                }
                catch (Exception exception2)
                {
                    flag      = true;
                    exception = exception2;
                }
                if (flag)
                {
                    string     text    = System.Windows.Forms.SR.GetString("ErrorPropertyPageFailed");
                    IUIService service = (context != null) ? ((IUIService)context.GetService(typeof(IUIService))) : null;
                    if (service == null)
                    {
                        RTLAwareMessageBox.Show(null, text, System.Windows.Forms.SR.GetString("PropertyGridTitle"), MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, 0);
                    }
                    else if (exception != null)
                    {
                        service.ShowError(exception, text);
                    }
                    else
                    {
                        service.ShowError(text);
                    }
                }
            }
            return(false);
        }
 public static bool NeedsComponentEditor(object obj)
 {
     if (obj is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
     {
         Guid empty = Guid.Empty;
         if ((((System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) obj).MapPropertyToPage(-1, out empty) == 0) && !empty.Equals(Guid.Empty))
         {
             return true;
         }
     }
     if (obj is System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)
     {
         try
         {
             System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
             try
             {
                 ((System.Windows.Forms.NativeMethods.ISpecifyPropertyPages) obj).GetPages(pPages);
                 if (pPages.cElems > 0)
                 {
                     return true;
                 }
             }
             finally
             {
                 if (pPages.pElems != IntPtr.Zero)
                 {
                     Marshal.FreeCoTaskMem(pPages.pElems);
                 }
             }
         }
         catch
         {
         }
     }
     return false;
 }
 public override bool EditComponent(ITypeDescriptorContext context, object obj, IWin32Window parent)
 {
     IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;
     if (obj is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
     {
         Guid empty = Guid.Empty;
         if ((((System.Windows.Forms.NativeMethods.IPerPropertyBrowsing) obj).MapPropertyToPage(-1, out empty) == 0) && !empty.Equals(Guid.Empty))
         {
             object pobjs = obj;
             Guid[] pClsid = new Guid[] { empty };
             SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref pobjs, 1, pClsid, Application.CurrentCulture.LCID, 0, IntPtr.Zero);
             return true;
         }
     }
     if (obj is System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)
     {
         Exception exception;
         bool flag = false;
         try
         {
             System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
             try
             {
                 ((System.Windows.Forms.NativeMethods.ISpecifyPropertyPages) obj).GetPages(pPages);
                 if (pPages.cElems <= 0)
                 {
                     return false;
                 }
             }
             catch
             {
                 return false;
             }
             try
             {
                 object obj3 = obj;
                 SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref obj3, pPages.cElems, new HandleRef(pPages, pPages.pElems), Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                 return true;
             }
             finally
             {
                 if (pPages.pElems != IntPtr.Zero)
                 {
                     Marshal.FreeCoTaskMem(pPages.pElems);
                 }
             }
         }
         catch (Exception exception2)
         {
             flag = true;
             exception = exception2;
         }
         if (flag)
         {
             string text = System.Windows.Forms.SR.GetString("ErrorPropertyPageFailed");
             IUIService service = (context != null) ? ((IUIService) context.GetService(typeof(IUIService))) : null;
             if (service == null)
             {
                 RTLAwareMessageBox.Show(null, text, System.Windows.Forms.SR.GetString("PropertyGridTitle"), MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, 0);
             }
             else if (exception != null)
             {
                 service.ShowError(exception, text);
             }
             else
             {
                 service.ShowError(text);
             }
         }
     }
     return false;
 }