2 // System.Windows.Forms.Design.StringCollectionEditor
5 // Ivan N. Zlatev <contact@i-nz.net>
7 // (C) 2007 Ivan N. Zlatev
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.ComponentModel
;
33 using System
.ComponentModel
.Design
;
34 using System
.Drawing
.Design
;
35 using System
.Windows
.Forms
;
37 namespace System
.Windows
.Forms
.Design
39 internal class StringCollectionEditor
: CollectionEditor
42 private class StringCollectionEditForm
: CollectionEditor
.CollectionForm
45 private System
.Windows
.Forms
.TextBox txtItems
;
46 private System
.Windows
.Forms
.Label label1
;
47 private System
.Windows
.Forms
.Button butOk
;
48 private System
.Windows
.Forms
.Button butCancel
;
50 public StringCollectionEditForm (CollectionEditor editor
) : base (editor
)
52 InitializeComponent ();
55 #region Windows Form Designer generated code
58 private void InitializeComponent()
60 this.txtItems
= new System
.Windows
.Forms
.TextBox();
61 this.label1
= new System
.Windows
.Forms
.Label();
62 this.butOk
= new System
.Windows
.Forms
.Button();
63 this.butCancel
= new System
.Windows
.Forms
.Button();
68 this.txtItems
.Anchor
= ((System
.Windows
.Forms
.AnchorStyles
)((((System
.Windows
.Forms
.AnchorStyles
.Top
| System
.Windows
.Forms
.AnchorStyles
.Bottom
)
69 | System
.Windows
.Forms
.AnchorStyles
.Left
)
70 | System
.Windows
.Forms
.AnchorStyles
.Right
)));
71 this.txtItems
.Location
= new System
.Drawing
.Point(12, 25);
72 this.txtItems
.Multiline
= true;
73 this.txtItems
.AcceptsTab
= true;
74 this.txtItems
.Name
= "txtItems";
75 this.txtItems
.ScrollBars
= System
.Windows
.Forms
.ScrollBars
.Both
;
76 this.txtItems
.Size
= new System
.Drawing
.Size(378, 168);
77 this.txtItems
.TabIndex
= 1;
81 this.label1
.AutoSize
= true;
82 this.label1
.Location
= new System
.Drawing
.Point(9, 9);
83 this.label1
.Name
= "label1";
84 this.label1
.Size
= new System
.Drawing
.Size(227, 13);
85 this.label1
.TabIndex
= 0;
86 this.label1
.Text
= "&Enter the strings in the collection (one per line):";
90 this.butOk
.Anchor
= ((System
.Windows
.Forms
.AnchorStyles
)((System
.Windows
.Forms
.AnchorStyles
.Bottom
| System
.Windows
.Forms
.AnchorStyles
.Right
)));
91 this.butOk
.DialogResult
= System
.Windows
.Forms
.DialogResult
.OK
;
92 this.butOk
.Location
= new System
.Drawing
.Point(234, 199);
93 this.butOk
.Name
= "butOk";
94 this.butOk
.Size
= new System
.Drawing
.Size(75, 23);
95 this.butOk
.TabIndex
= 3;
96 this.butOk
.Text
= "OK";
97 this.butOk
.Click
+= new System
.EventHandler(this.butOk_Click
);
101 this.butCancel
.Anchor
= ((System
.Windows
.Forms
.AnchorStyles
)((System
.Windows
.Forms
.AnchorStyles
.Bottom
| System
.Windows
.Forms
.AnchorStyles
.Right
)));
102 this.butCancel
.DialogResult
= System
.Windows
.Forms
.DialogResult
.Cancel
;
103 this.butCancel
.Location
= new System
.Drawing
.Point(315, 199);
104 this.butCancel
.Name
= "butCancel";
105 this.butCancel
.Size
= new System
.Drawing
.Size(75, 23);
106 this.butCancel
.TabIndex
= 4;
107 this.butCancel
.Text
= "Cancel";
108 this.butCancel
.Click
+= new System
.EventHandler(this.butCancel_Click
);
112 this.ClientSize
= new System
.Drawing
.Size(402, 228);
113 this.Controls
.Add(this.butCancel
);
114 this.Controls
.Add(this.butOk
);
115 this.Controls
.Add(this.label1
);
116 this.Controls
.Add(this.txtItems
);
117 this.CancelButton
= butCancel
;
118 this.MaximizeBox
= false;
119 this.MinimizeBox
= false;
120 this.Name
= "StringEditorForm";
121 this.Text
= "String Collection Editor";
122 this.ResumeLayout(false);
123 this.PerformLayout();
127 protected override void OnEditValueChanged ()
129 object[] items
= base.Items
;
130 string text
= String
.Empty
;
132 for (int i
=0; i
< items
.Length
; i
++) {
133 if (items
[i
] is string) {
134 text
+= ((string) items
[i
]);
135 if (i
!= items
.Length
- 1) // no new line after the last one
136 text
+= Environment
.NewLine
;
139 txtItems
.Text
= text
;
142 private void butOk_Click (object sender
, EventArgs e
)
144 if (this.txtItems
.Text
== String
.Empty
) {
145 base.Items
= new string[0];
147 string[] items
= txtItems
.Lines
;
148 bool lastLineEmpty
= items
[items
.Length
-1].Trim ().Length
== 0;
149 object[] objects
= new object[lastLineEmpty
? items
.Length
-1 : items
.Length
];
150 for (int i
=0; i
< objects
.Length
; i
++)
151 objects
[i
] = (object)items
[i
];
152 base.Items
= objects
;
156 private void butCancel_Click (object sender
, EventArgs e
)
162 public StringCollectionEditor (Type type
) : base (type
)
167 protected override CollectionEditor
.CollectionForm
CreateCollectionForm ()
169 return new StringCollectionEditForm (this);