// Licensed to the .NET Foundation under one or more agreements.
|
// The .NET Foundation licenses this file to you under the MIT license.
|
// See the LICENSE file in the project root for more information.
|
|
using System;
|
using System.ComponentModel;
|
using System.ComponentModel.Design;
|
using System.Windows.Forms;
|
|
namespace DPumpHydr.WinFrmUI.WenSkin.Design.Editor
|
{
|
public partial class StringCollectionEditor
|
{
|
/// <summary>
|
/// StringCollectionForm allows visible editing of a string array.
|
/// Each line in the edit box is an array entry.
|
/// </summary>
|
private class StringCollectionForm : CollectionForm
|
{
|
private Label _instruction;
|
private TextBox _textEntry;
|
private Button _okButton;
|
private Button _cancelButton;
|
|
private readonly StringCollectionEditor _editor;
|
|
/// <summary>
|
/// Constructs a StringCollectionForm.
|
/// </summary>
|
public StringCollectionForm(CollectionEditor editor)
|
: base(editor)
|
{
|
_editor = (StringCollectionEditor)editor;
|
InitializeComponent();
|
HookEvents();
|
}
|
|
private void Edit1_keyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode != Keys.Escape)
|
{
|
return;
|
}
|
|
_cancelButton.PerformClick();
|
e.Handled = true;
|
}
|
|
private void StringCollectionEditor_HelpButtonClicked(object sender, CancelEventArgs e)
|
{
|
e.Cancel = true;
|
_editor.ShowHelp();
|
}
|
|
private void Form_HelpRequested(object sender, HelpEventArgs e)
|
{
|
_editor.ShowHelp();
|
}
|
|
private void HookEvents()
|
{
|
_textEntry.KeyDown += new KeyEventHandler(Edit1_keyDown);
|
_okButton.Click += new EventHandler(OKButton_click);
|
HelpButtonClicked += new CancelEventHandler(StringCollectionEditor_HelpButtonClicked);
|
}
|
|
/// <summary>
|
/// NOTE: The following code is required by the form designer.
|
/// It can be modified using the form editor. Do not modify it using the code editor.
|
/// </summary>
|
private void InitializeComponent()
|
{
|
_instruction = new Label();
|
_textEntry = new TextBox();
|
_okButton = new Button();
|
_cancelButton = new Button();
|
SuspendLayout();
|
// instruction
|
//
|
this._instruction.AutoSize = true;
|
this._instruction.Location = new System.Drawing.Point(12, 9);
|
this._instruction.Name = "label1";
|
this._instruction.Size = new System.Drawing.Size(185, 12);
|
this._instruction.TabIndex = 1;
|
this._instruction.Text = "在集合中输入字符串(每行一个)";
|
_instruction.Name = "instruction";
|
//
|
// textEntry
|
//
|
this._textEntry.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
this._textEntry.Location = new System.Drawing.Point(14, 35);
|
this._textEntry.Multiline = true;
|
this._textEntry.Name = "textBox1";
|
this._textEntry.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
this._textEntry.Size = new System.Drawing.Size(560, 278);
|
this._textEntry.TabIndex = 0;
|
_textEntry.AcceptsTab = true;
|
_textEntry.AcceptsReturn = true;
|
_textEntry.Name = "textEntry";
|
//
|
// okButton
|
//
|
this._okButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
this._okButton.Location = new System.Drawing.Point(416, 319);
|
this._okButton.Name = "button1";
|
this._okButton.Size = new System.Drawing.Size(75, 30);
|
this._okButton.TabIndex = 2;
|
this._okButton.Text = "确定";
|
this._okButton.UseVisualStyleBackColor = true;
|
_okButton.DialogResult = DialogResult.OK;
|
_okButton.Name = "okButton";
|
//
|
// cancelButton
|
//
|
this._cancelButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
this._cancelButton.Location = new System.Drawing.Point(497, 319);
|
this._cancelButton.Name = "button2";
|
this._cancelButton.Size = new System.Drawing.Size(75, 30);
|
this._cancelButton.TabIndex = 3;
|
this._cancelButton.Text = "取消";
|
this._cancelButton.UseVisualStyleBackColor = true;
|
_cancelButton.DialogResult = DialogResult.Cancel;
|
_cancelButton.Name = "cancelButton";
|
//
|
// StringCollectionEditor
|
//
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.ClientSize = new System.Drawing.Size(584, 361);
|
this.Text = "字符串集合编辑器";
|
AutoScaleMode = AutoScaleMode.Font;
|
Controls.Add(_instruction);
|
Controls.Add(_textEntry);
|
Controls.Add(_okButton);
|
Controls.Add(_cancelButton);
|
|
MaximizeBox = false;
|
MinimizeBox = false;
|
Name = "StringCollectionEditor";
|
ShowIcon = false;
|
ShowInTaskbar = false;
|
HelpRequested += new HelpEventHandler(Form_HelpRequested);
|
ResumeLayout(false);
|
PerformLayout();
|
}
|
|
/// <summary>
|
/// Commits the changes to the editor.
|
/// </summary>
|
private void OKButton_click(object sender, EventArgs e)
|
{
|
char[] delims = new char[] { '\n' };
|
char[] trims = new char[] { '\r' };
|
|
string[] strings = _textEntry.Text.Split(delims);
|
object[] curItems = Items;
|
|
int nItems = strings.Length;
|
for (int i = 0; i < nItems; i++)
|
{
|
strings[i] = strings[i].Trim(trims);
|
}
|
|
bool dirty = true;
|
if (nItems == curItems.Length)
|
{
|
int i;
|
for (i = 0; i < nItems; ++i)
|
{
|
if (!strings[i].Equals((string)curItems[i]))
|
{
|
break;
|
}
|
}
|
|
if (i == nItems)
|
dirty = false;
|
}
|
|
if (!dirty)
|
{
|
DialogResult = DialogResult.Cancel;
|
return;
|
}
|
|
// If the final line is blank, we don't want to create an item from it
|
if (strings.Length > 0 && strings[strings.Length - 1].Length == 0)
|
{
|
nItems--;
|
}
|
|
object[] values = new object[nItems];
|
for (int i = 0; i < nItems; i++)
|
{
|
values[i] = strings[i];
|
}
|
|
Items = values;
|
}
|
|
/// <summary>
|
/// This is called when the value property in the CollectionForm has changed.
|
/// In it you should update your user interface to reflect the current value.
|
/// </summary>
|
protected override void OnEditValueChanged()
|
{
|
object[] items = Items;
|
string text = string.Empty;
|
|
for (int i = 0; i < items.Length; i++)
|
{
|
if (items[i] is string)
|
{
|
text += (string)items[i];
|
if (i != items.Length - 1)
|
{
|
text += "\r\n";
|
}
|
}
|
}
|
|
_textEntry.Text = text;
|
}
|
}
|
}
|
}
|