Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a custom control with extendable property "ButtonProperties " which has a custom form editor and it works perfectly fine
My proplem is when selecting more than one control the TextBoxes of the form will be blank instead of having values for the properties which are the same between the selected controls.
Notice: if all the properties are the same between all controls the values are appearing correctly
C#
public class ButtonEditor : UITypeEditor
    {

        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return
            UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorservice = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            Complex_Editor form = new Complex_Editor();
            ButtonProperties inobj = new ButtonProperties();
            ButtonProperties outobj = new ButtonProperties();
            inobj = (ButtonProperties)value;
            try
            {
                form.Controls["txtbxbtnText"].Text = inobj.Text;
            }
            catch
            {
            }
            try
            {
                form.Controls["txtbxbtnWidth"].Text = inobj.Width.ToString();
            }
            catch
            {
            }
            try
            {
                form.Controls["txtbxbtnHeight"].Text = inobj.Height.ToString();
            }
            catch
            {
            }
            form.ShowDialog();
            if (Variables.ValuesChanged == true)
            {
                if (!string.IsNullOrEmpty(form.Controls["txtbxbtnText"].Text))
                {
                    outobj.Text = form.Controls["txtbxbtnText"].Text;
                }
                if (!string.IsNullOrEmpty(form.Controls["txtbxbtnWidth"].Text))
                {
                    outobj.Width = int.Parse(form.Controls["txtbxbtnWidth"].Text);
                }
                if (!string.IsNullOrEmpty(form.Controls["txtbxbtnHeight"].Text))
                {
                    outobj.Height = int.Parse(form.Controls["txtbxbtnHeight"].Text);
                }
                return outobj;
            }
         return outobj;
        }
    }
}

code that solved my proplem:

    public class ButtonEditor : UITypeEditor
    {

        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return
            UITypeEditorEditStyle.Modal;
        }


        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorservice = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            Complex_Editor form = new Complex_Editor();
            ButtonProperties inobj = new ButtonProperties();
            ButtonProperties outobj = new ButtonProperties();
            List<neste> tempControls = new List<neste>();
            bool textFlag, widthFlag, heightFlag;
            textFlag = widthFlag = heightFlag = false;
            if (context.Instance.GetType().Name == "Object[]")
            {
                object[] controls = (object[])context.Instance;
                foreach (object control in controls)
                {
                    neste temp = (neste)control;
                    tempControls.Add(temp);
                }
                for (int i = 0; i < tempControls.Count; i++)
                {
                    if (tempControls[0].Button_Properties.Text != tempControls[i].Button_Properties.Text)
                    {
                        textFlag = false;
                        break;
                    }
                    textFlag = true;
                }

                for (int i = 0; i < tempControls.Count; i++)
                {
                    if (tempControls[0].Button_Properties.Width != tempControls[i].Button_Properties.Width)
                    {
                        widthFlag = false;
                        break;
                    }
                    widthFlag = true;
                }

                for (int i = 0; i < tempControls.Count; i++)
                {
                    if (tempControls[0].Button_Properties.Height != tempControls[i].Button_Properties.Height)
                    {
                        heightFlag = false;
                        break;
                    }
                    heightFlag = true;
                }
                if (textFlag)
                    inobj.Text = tempControls[0].Button_Properties.Text;
                else
                    inobj.Text = "";
                if (widthFlag)
                    inobj.Width = tempControls[0].Button_Properties.Width;
                else
                    inobj.Width = 0;
                if (heightFlag)
                    inobj.Height = tempControls[0].Button_Properties.Height;
                else
                    inobj.Height = 0;
            }
            else
            {
                inobj = (ButtonProperties)value;
            }
            try
            {
                form.Controls["txtbxbtnText"].Text = inobj.Text;
            }
            catch
            {
            }
            try
            {
                form.Controls["txtbxbtnWidth"].Text = inobj.Width.ToString();
            }
            catch
            {
            }
            try
            {
                form.Controls["txtbxbtnHeight"].Text = inobj.Height.ToString();
            }
            catch
            {
            }

            form.ShowDialog();
            if (Variables.ValuesChanged == true)
            {
                if (!string.IsNullOrEmpty(form.Controls["txtbxbtnText"].Text))
                {
                    outobj.Text = form.Controls["txtbxbtnText"].Text;
                }
                if (!string.IsNullOrEmpty(form.Controls["txtbxbtnWidth"].Text))
                {
                    outobj.Width = int.Parse(form.Controls["txtbxbtnWidth"].Text);
                }
                if (!string.IsNullOrEmpty(form.Controls["txtbxbtnHeight"].Text))
                {
                    outobj.Height = int.Parse(form.Controls["txtbxbtnHeight"].Text);
                }
                return outobj;
            }
            return base.EditValue(context, provider, value);
        }


    }
Posted
Updated 5-Jul-15 22:20pm
v2
Comments
Ralf Meier 6-Jul-15 2:14am    
For me it is not clear what the issue or the goal is.
Please explain it with further Information ... (or perhaps a screenshot).
Eng.Yahya92 6-Jul-15 2:33am    
this code represents custom editor for a custom property in a custom control
the proplem is: in design time when I select more than one control then I go to the properties custom editor, the editor values which are the same between all selected controls are blank in the editor instead of being filled with value
Ralf Meier 6-Jul-15 2:46am    
I understand the first part of it.
You build up your own UITypeEditor.
But the issue isn't clear for me.
But there is one Thing I have seen : why dont you give your UITypeEditor the customized property as one element ? - perhaps this is the Point ...
Ralf Meier 6-Jul-15 2:48am    
Additional :
Show me also the declaration of the customized property and the Connection of/to your Editor ...
Eng.Yahya92 6-Jul-15 2:49am    
because if there is some kind of failure I do not want the entire property to fail, instead a part of it will fail

1 solution

code that solved my proplem:

C#
public class ButtonEditor : UITypeEditor
   {

       public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
       {
           return
           UITypeEditorEditStyle.Modal;
       }


       public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
       {
           IWindowsFormsEditorService editorservice = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
           Complex_Editor form = new Complex_Editor();
           ButtonProperties inobj = new ButtonProperties();
           ButtonProperties outobj = new ButtonProperties();
           List<neste> tempControls = new List<neste>();
           bool textFlag, widthFlag, heightFlag;
           textFlag = widthFlag = heightFlag = false;
           if (context.Instance.GetType().Name == "Object[]")
           {
               object[] controls = (object[])context.Instance;
               foreach (object control in controls)
               {
                   neste temp = (neste)control;
                   tempControls.Add(temp);
               }
               for (int i = 0; i < tempControls.Count; i++)
               {
                   if (tempControls[0].Button_Properties.Text != tempControls[i].Button_Properties.Text)
                   {
                       textFlag = false;
                       break;
                   }
                   textFlag = true;
               }

               for (int i = 0; i < tempControls.Count; i++)
               {
                   if (tempControls[0].Button_Properties.Width != tempControls[i].Button_Properties.Width)
                   {
                       widthFlag = false;
                       break;
                   }
                   widthFlag = true;
               }

               for (int i = 0; i < tempControls.Count; i++)
               {
                   if (tempControls[0].Button_Properties.Height != tempControls[i].Button_Properties.Height)
                   {
                       heightFlag = false;
                       break;
                   }
                   heightFlag = true;
               }
               if (textFlag)
                   inobj.Text = tempControls[0].Button_Properties.Text;
               else
                   inobj.Text = "";
               if (widthFlag)
                   inobj.Width = tempControls[0].Button_Properties.Width;
               else
                   inobj.Width = 0;
               if (heightFlag)
                   inobj.Height = tempControls[0].Button_Properties.Height;
               else
                   inobj.Height = 0;
           }
           else
           {
               inobj = (ButtonProperties)value;
           }
           try
           {
               form.Controls["txtbxbtnText"].Text = inobj.Text;
           }
           catch
           {
           }
           try
           {
               form.Controls["txtbxbtnWidth"].Text = inobj.Width.ToString();
           }
           catch
           {
           }
           try
           {
               form.Controls["txtbxbtnHeight"].Text = inobj.Height.ToString();
           }
           catch
           {
           }

           form.ShowDialog();
           if (Variables.ValuesChanged == true)
           {
               if (!string.IsNullOrEmpty(form.Controls["txtbxbtnText"].Text))
               {
                   outobj.Text = form.Controls["txtbxbtnText"].Text;
               }
               if (!string.IsNullOrEmpty(form.Controls["txtbxbtnWidth"].Text))
               {
                   outobj.Width = int.Parse(form.Controls["txtbxbtnWidth"].Text);
               }
               if (!string.IsNullOrEmpty(form.Controls["txtbxbtnHeight"].Text))
               {
                   outobj.Height = int.Parse(form.Controls["txtbxbtnHeight"].Text);
               }
               return outobj;
           }
           return base.EditValue(context, provider, value);
       }
   }</neste></neste>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900