private void FormatControlFinishedLoading()
        {
            BindingFormattingDialog dialog  = null;
            FormatStringDialog      dialog2 = null;

            for (Control control = base.Parent; control != null; control = control.Parent)
            {
                dialog  = control as BindingFormattingDialog;
                dialog2 = control as FormatStringDialog;
                if ((dialog != null) || (dialog2 != null))
                {
                    break;
                }
            }
            if (dialog2 != null)
            {
                dialog2.FormatControlFinishedLoading();
            }
        }
示例#2
0
        // This method tells the FormatStringDialog that the FormatControl is loaded and resized.
        private void FormatControlFinishedLoading()
        {
            FormatStringDialog fsd = null;
            Control            ctl = Parent;

            while (ctl != null)
            {
                fsd = ctl as FormatStringDialog;

                if (fsd != null)
                {
                    break;
                }

                ctl = ctl.Parent;
            }

            if (fsd != null)
            {
                fsd.FormatControlFinishedLoading();
            }
        }
示例#3
0
        /// Edits the specified value using the specified provider within the specified context.
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider == null)
            {
                return(value);
            }

            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc == null)
            {
                return(value);
            }

            DataGridViewCellStyle dgvCellStyle = context.Instance as DataGridViewCellStyle;
            ListControl           listControl  = context.Instance as ListControl;

            Debug.Assert(listControl != null || dgvCellStyle != null, "this editor is used for the DataGridViewCellStyle::Format and the ListControl::FormatString properties");
            Application.SetHighDpiMode(HighDpiMode.SystemAware);

            if (_formatStringDialog == null)
            {
                _formatStringDialog = new FormatStringDialog(context);
            }

            if (listControl != null)
            {
                _formatStringDialog.ListControl = listControl;
            }
            else
            {
                _formatStringDialog.DataGridViewCellStyle = dgvCellStyle;
            }

            IComponentChangeService changeSvc = (IComponentChangeService)provider.GetService(typeof(IComponentChangeService));

            if (changeSvc != null)
            {
                if (dgvCellStyle != null)
                {
                    changeSvc.OnComponentChanging(dgvCellStyle, TypeDescriptor.GetProperties(dgvCellStyle)["Format"]);
                    changeSvc.OnComponentChanging(dgvCellStyle, TypeDescriptor.GetProperties(dgvCellStyle)["NullValue"]);
                    changeSvc.OnComponentChanging(dgvCellStyle, TypeDescriptor.GetProperties(dgvCellStyle)["FormatProvider"]);
                }
                else
                {
                    changeSvc.OnComponentChanging(listControl, TypeDescriptor.GetProperties(listControl)["FormatString"]);
                    changeSvc.OnComponentChanging(listControl, TypeDescriptor.GetProperties(listControl)["FormatInfo"]);
                }
            }

            edSvc.ShowDialog(_formatStringDialog);
            _formatStringDialog.End();

            if (!_formatStringDialog.Dirty)
            {
                return(value);
            }

            // since the bindings may have changed, the properties listed in the properties window need to be refreshed
            TypeDescriptor.Refresh(context.Instance);

            if (changeSvc != null)
            {
                if (dgvCellStyle != null)
                {
                    changeSvc.OnComponentChanged(dgvCellStyle, TypeDescriptor.GetProperties(dgvCellStyle)["Format"], null, null);
                    changeSvc.OnComponentChanged(dgvCellStyle, TypeDescriptor.GetProperties(dgvCellStyle)["NullValue"], null, null);
                    changeSvc.OnComponentChanged(dgvCellStyle, TypeDescriptor.GetProperties(dgvCellStyle)["FormatProvider"], null, null);
                }
                else
                {
                    changeSvc.OnComponentChanged(listControl, TypeDescriptor.GetProperties(listControl)["FormatString"], null, null);
                    changeSvc.OnComponentChanged(listControl, TypeDescriptor.GetProperties(listControl)["FormatInfo"], null, null);
                }
            }

            return(value);
        }
示例#4
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (service == null)
         {
             return(value);
         }
         DataGridViewCellStyle instance  = context.Instance as DataGridViewCellStyle;
         ListControl           component = context.Instance as ListControl;
         if (this.formatStringDialog == null)
         {
             this.formatStringDialog = new FormatStringDialog(context);
         }
         if (component != null)
         {
             this.formatStringDialog.ListControl = component;
         }
         else
         {
             this.formatStringDialog.DataGridViewCellStyle = instance;
         }
         IComponentChangeService service2 = (IComponentChangeService)provider.GetService(typeof(IComponentChangeService));
         if (service2 != null)
         {
             if (instance != null)
             {
                 service2.OnComponentChanging(instance, TypeDescriptor.GetProperties(instance)["Format"]);
                 service2.OnComponentChanging(instance, TypeDescriptor.GetProperties(instance)["NullValue"]);
                 service2.OnComponentChanging(instance, TypeDescriptor.GetProperties(instance)["FormatProvider"]);
             }
             else
             {
                 service2.OnComponentChanging(component, TypeDescriptor.GetProperties(component)["FormatString"]);
                 service2.OnComponentChanging(component, TypeDescriptor.GetProperties(component)["FormatInfo"]);
             }
         }
         service.ShowDialog(this.formatStringDialog);
         this.formatStringDialog.End();
         if (!this.formatStringDialog.Dirty)
         {
             return(value);
         }
         TypeDescriptor.Refresh(context.Instance);
         if (service2 == null)
         {
             return(value);
         }
         if (instance != null)
         {
             service2.OnComponentChanged(instance, TypeDescriptor.GetProperties(instance)["Format"], null, null);
             service2.OnComponentChanged(instance, TypeDescriptor.GetProperties(instance)["NullValue"], null, null);
             service2.OnComponentChanged(instance, TypeDescriptor.GetProperties(instance)["FormatProvider"], null, null);
             return(value);
         }
         service2.OnComponentChanged(component, TypeDescriptor.GetProperties(component)["FormatString"], null, null);
         service2.OnComponentChanged(component, TypeDescriptor.GetProperties(component)["FormatInfo"], null, null);
     }
     return(value);
 }
示例#5
0
        /// Edits the specified value using the specified provider within the specified context.
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (!provider.TryGetService(out IWindowsFormsEditorService editorService))
            {
                return(value);
            }

            var cellStyle   = context.Instance as DataGridViewCellStyle;
            var listControl = context.Instance as ListControl;

            Debug.Assert(
                listControl is not null || cellStyle is not null,
                "this editor is used for the DataGridViewCellStyle::Format and the ListControl::FormatString properties");

            Application.SetHighDpiMode(HighDpiMode.SystemAware);

            _formatStringDialog ??= new FormatStringDialog(context);

            if (listControl is not null)
            {
                _formatStringDialog.ListControl = listControl;
            }
            else
            {
                _formatStringDialog.DataGridViewCellStyle = cellStyle;
            }

            if (provider.TryGetService(out IComponentChangeService changeService))
            {
                if (cellStyle is not null)
                {
                    changeService.OnComponentChanging(cellStyle, TypeDescriptor.GetProperties(cellStyle)["Format"]);
                    changeService.OnComponentChanging(cellStyle, TypeDescriptor.GetProperties(cellStyle)["NullValue"]);
                    changeService.OnComponentChanging(cellStyle, TypeDescriptor.GetProperties(cellStyle)["FormatProvider"]);
                }
                else
                {
                    changeService.OnComponentChanging(listControl, TypeDescriptor.GetProperties(listControl)["FormatString"]);
                    changeService.OnComponentChanging(listControl, TypeDescriptor.GetProperties(listControl)["FormatInfo"]);
                }
            }

            editorService.ShowDialog(_formatStringDialog);
            FormatStringDialog.End();

            if (!_formatStringDialog.Dirty)
            {
                return(value);
            }

            // Since the bindings may have changed, the properties listed in the properties window need to be refreshed.
            TypeDescriptor.Refresh(context.Instance);

            if (changeService is not null)
            {
                if (cellStyle is not null)
                {
                    changeService.OnComponentChanged(cellStyle, TypeDescriptor.GetProperties(cellStyle)["Format"]);
                    changeService.OnComponentChanged(cellStyle, TypeDescriptor.GetProperties(cellStyle)["NullValue"]);
                    changeService.OnComponentChanged(cellStyle, TypeDescriptor.GetProperties(cellStyle)["FormatProvider"]);
                }
                else
                {
                    changeService.OnComponentChanged(listControl, TypeDescriptor.GetProperties(listControl)["FormatString"]);
                    changeService.OnComponentChanged(listControl, TypeDescriptor.GetProperties(listControl)["FormatInfo"]);
                }
            }

            return(value);
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (provider != null)
     {
         IWindowsFormsEditorService service = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));
         if (service == null)
         {
             return value;
         }
         DataGridViewCellStyle instance = context.Instance as DataGridViewCellStyle;
         ListControl component = context.Instance as ListControl;
         if (this.formatStringDialog == null)
         {
             this.formatStringDialog = new FormatStringDialog(context);
         }
         if (component != null)
         {
             this.formatStringDialog.ListControl = component;
         }
         else
         {
             this.formatStringDialog.DataGridViewCellStyle = instance;
         }
         IComponentChangeService service2 = (IComponentChangeService) provider.GetService(typeof(IComponentChangeService));
         if (service2 != null)
         {
             if (instance != null)
             {
                 service2.OnComponentChanging(instance, TypeDescriptor.GetProperties(instance)["Format"]);
                 service2.OnComponentChanging(instance, TypeDescriptor.GetProperties(instance)["NullValue"]);
                 service2.OnComponentChanging(instance, TypeDescriptor.GetProperties(instance)["FormatProvider"]);
             }
             else
             {
                 service2.OnComponentChanging(component, TypeDescriptor.GetProperties(component)["FormatString"]);
                 service2.OnComponentChanging(component, TypeDescriptor.GetProperties(component)["FormatInfo"]);
             }
         }
         service.ShowDialog(this.formatStringDialog);
         this.formatStringDialog.End();
         if (!this.formatStringDialog.Dirty)
         {
             return value;
         }
         TypeDescriptor.Refresh(context.Instance);
         if (service2 == null)
         {
             return value;
         }
         if (instance != null)
         {
             service2.OnComponentChanged(instance, TypeDescriptor.GetProperties(instance)["Format"], null, null);
             service2.OnComponentChanged(instance, TypeDescriptor.GetProperties(instance)["NullValue"], null, null);
             service2.OnComponentChanged(instance, TypeDescriptor.GetProperties(instance)["FormatProvider"], null, null);
             return value;
         }
         service2.OnComponentChanged(component, TypeDescriptor.GetProperties(component)["FormatString"], null, null);
         service2.OnComponentChanged(component, TypeDescriptor.GetProperties(component)["FormatInfo"], null, null);
     }
     return value;
 }