string CreateForm(string TextboxValue)
{
string ret = string.Empty;
#region create form
using (Form f = new Form())
{
Label lbl = new Label();
lbl.Text = "Group Name";
lbl.Location = new Point(3, 3);
TextBox txGroup = new TextBox();
txGroup.Text = TextboxValue;
txGroup.SelectAll();
txGroup.Location = new Point(lbl.Location.X, lbl.Location.Y + lbl.Size.Height + 3);
txGroup.Width = 200;
Button btnCreate = new Button();
btnCreate.Text = "Create";
btnCreate.Location = new Point(lbl.Location.X, txGroup.Location.Y + txGroup.Size.Height + 3);
btnCreate.Click += new EventHandler(delegate
{
if (txGroup.Text == string.Empty)
{
MessageBox.Show("Please enter a group name", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
ret = txGroup.Text;
f.DialogResult = DialogResult.OK;
f.Close();
}
});
Button btnCancel = new Button();
btnCancel.Text = "Cancel";
btnCancel.Location = new Point(btnCreate.Location.X + btnCreate.Size.Width + 3, btnCreate.Location.Y);
btnCancel.Click += new EventHandler(delegate
{
ret = null;
f.DialogResult = DialogResult.Cancel;
f.Close();
});
f.FormBorderStyle = FormBorderStyle.FixedDialog;
f.MaximizeBox = false;
f.MinimizeBox = false;
f.ControlBox = false;
f.StartPosition = FormStartPosition.CenterParent;
f.AcceptButton = btnCreate;
f.CancelButton = btnCancel;
f.ClientSize = new Size(
txGroup.Location.X + txGroup.Size.Width + 3,
btnCreate.Location.Y + btnCreate.Size.Height + 3
);
f.Controls.AddRange(new Control[] {
lbl, txGroup, btnCreate, btnCancel
});
DialogResult dr = f.ShowDialog();
if (dr == DialogResult.Cancel)
{
f.Dispose();
return ret;
}
}
#endregion
return ret;
}