110,579
社区成员
发帖
与我相关
我的任务
分享
public class My : Component
{
private string[] defaultLines;
private string[] myLines;
[Editor("System.Windows.Forms.Design.StringArrayEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public string[] DefaultTextBoxLines { get { return this.defaultLines; } set { this.defaultLines = value; } }
[Editor( typeof(MyEditor), typeof(UITypeEditor))]
public string[] MyLines { get { return this.myLines; } set { this.myLines = value; } }
}
public class MyEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
MyEditorForm editorForm = new MyEditorForm(value as string[]);
editorService.ShowDialog( editorForm );
return editorForm.Lines;
}
private class MyEditorForm : Form
{
public MyEditorForm(string[] lines)
{
InitializeComponent();
this.textBox.Lines = lines;
}
public string[] Lines
{
get { return this.textBox.Lines; }
}
void InitializeComponent()
{
textBox.Multiline = true;
textBox.Dock = DockStyle.Top;
textBox.Height = 200;
okButton.Text = "&Ok";
okButton.Dock = DockStyle.Bottom;
okButton.DialogResult = DialogResult.OK;
okButton.Height = this.ClientRectangle.Height - textBox.Height;
this.Controls.Add(textBox);
this.Controls.Add(okButton);
this.StartPosition = FormStartPosition.CenterScreen;
}
TextBox textBox = new TextBox();
Button okButton = new Button();
}
}