public static string GetTextInput(Form caller, string text, string title)
        {
            DlgText dlg = new DlgText();

            dlg.LoadData(text, title);
            if (dlg.ShowDialog(caller) == DialogResult.OK)
            {
                return(dlg.GetText());
            }
            return(null);
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
         if (edSvc != null)
         {
             DlgText dlg = new DlgText();
             dlg.LoadData(value as string, string.Format(CultureInfo.InvariantCulture, "Modify {0}", context.PropertyDescriptor.Name));
             if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
             {
                 value = dlg.GetText();
             }
         }
     }
     return(value);
 }
예제 #3
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    ITypedNamedValuesHolder vep = context.Instance as ITypedNamedValuesHolder;
                    if (vep != null)
                    {
                        CommandList list = new CommandList(edSvc);
                        edSvc.DropDownControl(list);
                        if (list.MadeSelection)
                        {
                            bool edited = false;
                            switch (list.Selection)
                            {
                            case 0:
                                DlgNewTypedNamedValue dlg = new DlgNewTypedNamedValue();
                                TypedNamedValue       tn  = vep.GetTypedNamedValueByName(context.PropertyDescriptor.Name);
                                dlg.LoadData(vep.GetValueNames(), "Modify value name and type", tn);
                                if (edSvc.ShowDialog(dlg) == System.Windows.Forms.DialogResult.OK)
                                {
                                    edited = vep.RenameTypedNamedValue(context.PropertyDescriptor.Name, dlg.DataName, dlg.DataType);
                                }
                                break;

                            case 1:
                                DlgText dlgt = new DlgText();
                                dlgt.LoadData(value as string, string.Format(CultureInfo.InvariantCulture, "Modify {0}", context.PropertyDescriptor.Name));
                                if (edSvc.ShowDialog(dlgt) == DialogResult.OK)
                                {
                                    value = dlgt.GetText();
                                }
                                break;

                            case 2:
                                edited = vep.DeleteTypedNamedValue(context.PropertyDescriptor.Name);
                                break;
                            }
                            if (edited)
                            {
                                PropertyGrid pg   = null;
                                Type         t    = edSvc.GetType();
                                PropertyInfo pif0 = t.GetProperty("OwnerGrid");
                                if (pif0 != null)
                                {
                                    object g = pif0.GetValue(edSvc, null);
                                    pg = g as PropertyGrid;
                                    if (pg != null)
                                    {
                                        pg.Refresh();
                                    }
                                }
                                PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(context.Instance, true);
                                PropertyDescriptor           p  = ps["Dummy"];
                                if (p != null)
                                {
                                    p.SetValue(context.Instance, Guid.NewGuid().GetHashCode());
                                }
                                IPropertyListchangeable plc = context.Instance as IPropertyListchangeable;
                                if (plc != null)
                                {
                                    plc.OnPropertyListChanged();
                                }
                            }
                        }
                    }
                }
            }
            return(value);
        }