using System; using System.Drawing; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Windows.Forms; namespace m { /// /// Summary description for PickListForm. /// public class PickListForm : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Button buttonOk; private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.ListBox listBox1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public PickListForm(string strTitle, string strCurrent, StringCollection strc) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // listBox1.DataSource = strc; listBox1.SelectedIndex = strCurrent == "" ? -1 : strc.IndexOf(strCurrent); Text = strTitle; label1.Text = label1.Text.Replace("$1", strTitle); } public int GetIndex() { return listBox1.SelectedIndex; } static public int DoModal(string strTitle, string strCurrent, StringCollection strc) { PickListForm frm = new PickListForm(strTitle, strCurrent, strc); DialogResult res = frm.ShowDialog(); if (res == DialogResult.Cancel) return -1; return frm.GetIndex(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.buttonOk = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.listBox1 = new System.Windows.Forms.ListBox(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(8, 8); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(200, 16); this.label1.TabIndex = 0; this.label1.Text = "Choose one $1:"; // // buttonOk // this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK; this.buttonOk.Location = new System.Drawing.Point(32, 344); this.buttonOk.Name = "buttonOk"; this.buttonOk.TabIndex = 2; this.buttonOk.Text = "Ok"; this.buttonOk.Click += new System.EventHandler(this.buttonOk_Click); // // buttonCancel // this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.Location = new System.Drawing.Point(144, 344); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.TabIndex = 2; this.buttonCancel.Text = "Cancel"; this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); // // listBox1 // this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.listBox1.ItemHeight = 16; this.listBox1.Location = new System.Drawing.Point(8, 24); this.listBox1.Name = "listBox1"; this.listBox1.Size = new System.Drawing.Size(232, 308); this.listBox1.TabIndex = 3; this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick); // // PickListForm // this.AcceptButton = this.buttonOk; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.CancelButton = this.buttonCancel; this.ClientSize = new System.Drawing.Size(250, 376); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.listBox1, this.buttonOk, this.label1, this.buttonCancel}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "PickListForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "PickListForm"; this.ResumeLayout(false); } #endregion private void buttonOk_Click(object sender, System.EventArgs e) { DialogResult = DialogResult.OK; } private void buttonCancel_Click(object sender, System.EventArgs e) { DialogResult = DialogResult.Cancel; } private void listBox1_DoubleClick(object sender, System.EventArgs e) { DialogResult = DialogResult.OK; } } }