StringCollectionEditor.cs 5.6 KB

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