选择多个控件时如何显示自定义编辑器值 [英] how to make custom editor values appear when selecting more than one control
问题描述
我创建了一个带有可扩展属性ButtonProperties的自定义控件,它有一个自定义表单编辑器,它工作得非常好
我的问题是在选择多个控件时,表单的TextBox会为空白而不是在所选控件之间具有相同属性的值。
注意:如果所有控件之间的所有属性都相同,则值正确显示
< pre lang =c#> public class ButtonEditor:UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return
UITypeEditorEditStyle.Modal;
}
public 覆盖 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 ;
尝试
{
form.Controls [ txtbxbtnText]。Text = inobj.Text;
}
catch
{
}
try
{
form.Controls [ txtbxbtnWidth]。 = inobj.Width.ToString();
}
catch
{
}
try
{
form.Controls [ txtbxbtnHeight]。 = inobj.Height.ToString();
}
catch
{
}
form.ShowDialog();
if (Variables.ValuesChanged == true )
{
if (!string.IsNullOrEmpty(form.Controls [ txtbxbtnText]。文本))
{
outobj.Text = form.Controls [ txtbxbtnText跨度>]文本。
}
if (!string.IsNullOrEmpty(form.Controls [ < span class =code-string> txtbxbtnWidth]。文本))
{
outobj.Width = int .Parse (form.Controls [ txtbxbtnWidth]。Text);
}
if (!string.IsNullOrEmpty(form.Controls [ < span class =code-string> txtbxbtnHeight]。文本))
{
outobj.Height = int .Parse (form.Controls [ txtbxbtnHeight]。Text);
}
return outobj;
}
return outobj;
}
}
}
代码解决了我的问题:
public class ButtonEditor:UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return
UITypeEditorEditStyle.Modal;
}
public 覆盖 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();
列表< neste> tempControls = new 列表< neste>();
bool textFlag,widthFlag,heightFlag;
textFlag = widthFlag = heightFlag = false ;
if (context.Instance.GetType()。Name == Object [])
{
object [] controls =(对象跨度> [])context.Instance;
foreach ( object control in 控制)
{
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 。宽度;
else
inobj.Width = 0 ;
if (heightFlag)
inobj.Height = tempControls [ 0 ]。Button_Properties 。高度;
else
inobj.Height = 0 ;
}
else
{
inobj =(ButtonProperties) value < /跨度>;
}
尝试
{
form.Controls [ txtbxbtnText]。Text = inobj.Text;
}
catch
{
}
try
{
form.Controls [ txtbxbtnWidth]。 = inobj.Width.ToString();
}
catch
{
}
try
{
form.Controls [ txtbxbtnHeight]。 = inobj.Height.ToString();
}
catch
{
}
form.ShowDialog();
if (Variables.ValuesChanged == true )
{
if (!string.IsNullOrEmpty(form.Controls [ txtbxbtnText]。文本))
{
outobj.Text = form.Controls [ txtbxbtnText跨度>]文本。
}
if (!string.IsNullOrEmpty(form.Controls [ < span class =code-string> txtbxbtnWidth]。文本))
{
outobj.Width = int .Parse (form.Controls [ txtbxbtnWidth]。Text);
}
if (!string.IsNullOrEmpty(form.Controls [ < span class =code-string> txtbxbtnHeight]。文本))
{
outobj.Height = int .Parse (form.Controls [ txtbxbtnHeight]。Text);
}
return outobj;
}
return base .EditValue(context,provider,值跨度>);
}
} 解决了我的问题的代码:
public class ButtonEditor:UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle (System.ComponentModel.ITypeDescriptorContext context)
{
return
UITypeEditorEditStyle.Modal;
}
public 覆盖 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();
列表< neste> tempControls = new 列表< neste>();
bool textFlag,widthFlag,heightFlag;
textFlag = widthFlag = heightFlag = false ;
if (context.Instance.GetType()。Name == Object [])
{
object [] controls =(对象跨度> [])context.Instance;
foreach ( object control in 控制)
{
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 。宽度;
else
inobj.Width = 0 ;
if (heightFlag)
inobj.Height = tempControls [ 0 ]。Button_Properties 。高度;
else
inobj.Height = 0 ;
}
else
{
inobj =(ButtonProperties) value < /跨度>;
}
尝试
{
form.Controls [ txtbxbtnText]。Text = inobj.Text;
}
catch
{
}
try
{
form.Controls [ txtbxbtnWidth]。 = inobj.Width.ToString();
}
catch
{
}
try
{
form.Controls [ txtbxbtnHeight]。 = inobj.Height.ToString();
}
catch
{
}
form.ShowDialog();
if (Variables.ValuesChanged == true )
{
if (!string.IsNullOrEmpty(form.Controls [ txtbxbtnText]。文本))
{
outobj.Text = form.Controls [ txtbxbtnText跨度>]文本。
}
if (!string.IsNullOrEmpty(form.Controls [ < span class =code-string> txtbxbtnWidth]。文本))
{
outobj.Width = int .Parse (form.Controls [ txtbxbtnWidth]。Text);
}
if (!string.IsNullOrEmpty(form.Controls [ < span class =code-string> txtbxbtnHeight]。文本))
{
outobj.Height = int .Parse (form.Controls [ txtbxbtnHeight]。Text);
}
return outobj;
}
return base .EditValue(context,provider,值跨度>);
}
} < / neste > < / neste >
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
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);
}
}
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); } }</neste></neste>
这篇关于选择多个控件时如何显示自定义编辑器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!