本文整理汇总了C#中System.Windows.Forms.Label.SetBounds方法的典型用法代码示例。如果您正苦于以下问题:C# Label.SetBounds方法的具体用法?C# Label.SetBounds怎么用?C# Label.SetBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Label
的用法示例。
在下文中一共展示了Label.SetBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixControlSizes
private static void FixControlSizes(Label label, TextBox textBox, Button buttonOk, Button buttonCancel)
{
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
}
示例2: btnPeople_Click
void btnPeople_Click(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine(this.GetType().Attributes);
Form f = new Form();
Label lbl1, lbl2;
TextBox txt1, txt2;
f.Text = "WTF you are ?";
f.SetBounds(10, 10, 200, 140);
f.Controls.Add(lbl1 = new Label());
lbl1.SetBounds(5, 5, 185,18);
lbl1.Text = "firstname";
f.Controls.Add(txt1 = new TextBox());
txt1.SetBounds(5, 25, 185, 18);
f.Controls.Add(lbl2 = new Label());
lbl2.Text = "surname";
lbl2.SetBounds(5, 45, 185, 18);
f.Controls.Add(txt2 = new TextBox());
txt2.SetBounds(5, 65, 185, 18);
Button btn = new Button();
btn.SetBounds(5, 85, 185, 18);
btn.Text = "Add people";
f.Controls.Add(btn);
btn.Click += (object sender1, EventArgs e1) =>
{
this.chklistPeople.Items.Add(txt1.Text + " " + txt2.Text);
//this.Show();
//f.Close();
};
f.Show();
}
示例3: addLabel
public void addLabel( string text, int x, int y, int w, int h)
{
Label lab = new Label();
lab.Text = text;
lab.SetBounds(x, y, w, h);
Controls.Add(lab);
}
示例4: Show
/// <summary>
/// Shows a dialog box with an input field.
/// </summary>
/// <param name="title"></param>
/// <param name="prompt"></param>
/// <param name="value"></param>
/// <returns></returns>
public static DialogResult Show(string title, string prompt, ref string value)
{
Form mForm = new Form();
Label mLabel = new Label();
TextBox mTextBox = new TextBox();
Button mOKButton = new Button();
mForm.Text = title;
mLabel.Text = prompt;
mTextBox.Text = value;
mOKButton.Text = "OK";
mOKButton.DialogResult = DialogResult.OK;
mForm.ClientSize = new Size(240, 80);
mLabel.SetBounds(4, 4, mForm.ClientSize.Width-8, 22);
mTextBox.SetBounds(32, 26, mForm.ClientSize.Width - 64, 24);
mOKButton.SetBounds(mForm.ClientSize.Width / 2 - 32, 54, 64, 22);
mLabel.AutoSize = true;
mTextBox.Anchor = AnchorStyles.Bottom;
mOKButton.Anchor = AnchorStyles.Bottom;
mForm.Controls.AddRange(new Control[] { mLabel, mTextBox, mOKButton });
mForm.FormBorderStyle = FormBorderStyle.FixedDialog;
mForm.StartPosition = FormStartPosition.CenterScreen;
mForm.MinimizeBox = false;
mForm.MaximizeBox = false;
mForm.AcceptButton = mOKButton;
DialogResult dialogResult = mForm.ShowDialog();
value = mTextBox.Text;
return dialogResult;
}
示例5: Formulario
public Formulario(int qtdeVariaveis, int qtdeRestricoes)
{
InitializeComponent();
contadorEixoY = 40;
for (int i = 0; i < qtdeRestricoes; i++)
{
contadorEixoX = 100;
Label lbRestricoes = new Label();
lbRestricoes.SetBounds(10, contadorEixoY, 80, 25);
lbRestricoes.Text = "Restricao " + (i+1).ToString();
this.Controls.Add(lbRestricoes);
for (int j = 0; j < qtdeVariaveis; j++)
{
Label lbVariaveis = new Label();
lbVariaveis.SetBounds(contadorEixoX, 10, 30, 25);
lbVariaveis.Text = "X" + (j+1).ToString();
this.Controls.Add(lbVariaveis);
TextBox txt = new TextBox();
txt.SetBounds(contadorEixoX, contadorEixoY, 30, 30);
this.Controls.Add(txt);
contadorEixoX += 40;
}
contadorEixoY += 30;
}
}
示例6: inputBox
public static DialogResult inputBox(string title, string labelText, ref string promptText)
{
Form form = new Form();
Label label = new Label();
Button buttonOk = new Button();
Button buttonCancel = new Button();
TextBox textBox = new TextBox();
label.Text = labelText;
form.Text = title;
textBox.Text = promptText;
buttonOk.Text = "Ok";
buttonCancel.Text = "Cancelar";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
DialogResult res = form.ShowDialog();
promptText = textBox.Text;
return res;
}
示例7: InitEditors
public void InitEditors()
{
const int startX = 20, labelWd = 170, labelHt = 18, editorWd = 100, editorLeft = 198;
const int startY = 20, deltaY = 22;
var row = 0;
foreach (var ptr in CodeTemplate.parameters.Values)
{
var top = startY + (row++)*deltaY;
// подпись
var lbl = new Label {Text = ptr.Title, Parent = panelControls};
lbl.SetBounds(startX, top, labelWd, labelHt);
panelControls.Controls.Add(lbl);
// редактор значения
if (ptr.IsNumber || ptr.IsString)
{
var textBox = new TextBox {Parent = panelControls};
textBox.SetBounds(editorLeft, top, editorWd, labelHt + 2);
panelControls.Controls.Add(textBox);
paramEditors.Add(textBox);
}
if (ptr.IsBoolean)
{
var checkBox = new CheckBox {Parent = panelControls, Left = editorLeft, Top = top};
panelControls.Controls.Add(checkBox);
paramEditors.Add(checkBox);
}
}
}
示例8: QuitDialog
//UPGRADE_TODO: Class 'java.awt.Frame' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtFrame'"
public QuitDialog(System.Windows.Forms.Form parent, bool modal)
: base()
{
//UPGRADE_TODO: Constructor 'java.awt.Dialog.Dialog' was converted to 'SupportClass.DialogSupport.SetDialog' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtDialogDialog_javaawtFrame_boolean'"
SupportClass.DialogSupport.SetDialog(this, parent);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
//UPGRADE_ISSUE: Method 'java.awt.Container.setLayout' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtContainersetLayout_javaawtLayoutManager'"
/*
setLayout(null);*/
//UPGRADE_TODO: Method 'java.awt.Component.setSize' was converted to 'System.Windows.Forms.Control.Size' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtComponentsetSize_int_int'"
Size = new System.Drawing.Size(SupportClass.GetInsets(this)[1] + SupportClass.GetInsets(this)[2] + 337, SupportClass.GetInsets(this)[0] + SupportClass.GetInsets(this)[3] + 135);
System.Windows.Forms.Button temp_Button;
temp_Button = new System.Windows.Forms.Button();
temp_Button.Text = " Yes ";
yesButton = temp_Button;
yesButton.SetBounds(SupportClass.GetInsets(this)[1] + 72, SupportClass.GetInsets(this)[0] + 80, 79, 22);
//UPGRADE_NOTE: If the given Font Name does not exist, a default Font instance is created. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1075'"
yesButton.Font = new System.Drawing.Font("Dialog", 12, System.Drawing.FontStyle.Bold);
//UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent'"
Controls.Add(yesButton);
System.Windows.Forms.Button temp_Button2;
temp_Button2 = new System.Windows.Forms.Button();
temp_Button2.Text = " No ";
noButton = temp_Button2;
noButton.SetBounds(SupportClass.GetInsets(this)[1] + 185, SupportClass.GetInsets(this)[0] + 80, 79, 22);
//UPGRADE_NOTE: If the given Font Name does not exist, a default Font instance is created. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1075'"
noButton.Font = new System.Drawing.Font("Dialog", 12, System.Drawing.FontStyle.Bold);
//UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent'"
Controls.Add(noButton);
System.Windows.Forms.Label temp_Label;
//UPGRADE_TODO: The equivalent in .NET for field 'java.awt.Label.CENTER' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
temp_Label = new System.Windows.Forms.Label();
temp_Label.Text = "Do you really want to quit?";
temp_Label.TextAlign = (System.Drawing.ContentAlignment) System.Drawing.ContentAlignment.MiddleCenter;
label1 = temp_Label;
label1.SetBounds(78, 33, 180, 23);
//UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent'"
Controls.Add(label1);
Text = "A Basic Application - Quit";
FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow(this);
//UPGRADE_NOTE: Some methods of the 'java.awt.event.WindowListener' class are not used in the .NET Framework. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1308'"
this.Closing += new System.ComponentModel.CancelEventHandler(aSymWindow.windowClosing);
SymAction lSymAction = new SymAction(this);
noButton.Click += new System.EventHandler(lSymAction.actionPerformed);
SupportClass.CommandManager.CheckCommand(noButton);
yesButton.Click += new System.EventHandler(lSymAction.actionPerformed);
SupportClass.CommandManager.CheckCommand(yesButton);
//}}
}
示例9: createNewLabel
private void createNewLabel(int x, int y, int width, int height, string text)
{
Label newLabel = new Label();
newLabel.Parent = this;
newLabel.Text = text;
newLabel.SetBounds(x, y, width, height);
newLabel.Show();
}
示例10: CatBox
public DialogResult CatBox(string promptText, double cost, DateTime dt, ref string value)
{
Form form = new Form();
Label label = new Label();
Label amount = new Label();
Label date = new Label();
ComboBox comboBox = new ComboBox();
Button buttonOk = new Button();
CheckBox checkBox = new CheckBox();
form.Text = "Specify a Category:";
label.Text = promptText;
amount.Text = cost.ToString("C");
date.Text = dt.ToString();
checkBox.Text = "Remember this relationship?";
buttonOk.Text = "OK";
buttonOk.DialogResult = DialogResult.OK;
label.SetBounds(9, 20, 172, 13);
amount.SetBounds(273, 20, 100, 13);
date.SetBounds(173, 20, 100, 13);
comboBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(309, 72, 75, 23);
checkBox.SetBounds(12, 72, 275, 24); // ???
label.AutoSize = true;
comboBox.Anchor = comboBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
checkBox.Anchor = checkBox.Anchor | AnchorStyles.Right;
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, amount, date, checkBox, comboBox, buttonOk });
form.ClientSize = new Size(Math.Max(300, amount.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
SqlCeConnection cs = new SqlCeConnection(@"Data Source = Expenses.sdf");
cs.Open();
SqlCeDataReader r = null;
SqlCeCommand getCats = new SqlCeCommand("SELECT * FROM Categories", cs);
r = getCats.ExecuteReader();
while (r.Read()) comboBox.Items.Add(r["Category"]);
cs.Close();
DialogResult dialogResult = form.ShowDialog();
value = comboBox.Text;
// remember relationship if option to do so is checked
if (checkBox.Checked)
{
SqlCeConnection cs2 = new SqlCeConnection(@"Data Source = Expenses.sdf");
cs2.Open();
SqlCeCommand setCat = new SqlCeCommand("INSERT INTO CategorizedItems VALUES (@Description, @Category)", cs2);
setCat.Parameters.AddWithValue("@Description", promptText);
setCat.Parameters.AddWithValue("@Category", value);
setCat.ExecuteNonQuery();
cs2.Close();
}
return dialogResult;
}
示例11: Show
public static DialogResult Show(string title, string promptText, ref string value,
InputBoxValidation validation)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
if (validation != null)
{
form.FormClosing += delegate(object sender, FormClosingEventArgs e)
{
if (form.DialogResult == DialogResult.OK)
{
string errorText = validation(textBox.Text);
if (e.Cancel = (errorText != ""))
{
MessageBox.Show(form, errorText, "Validation Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
textBox.Focus();
}
}
};
}
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
示例12: Show
/// <summary>
/// Displays a dialog with a prompt and textbox where the user can enter information
/// </summary>
/// <param name="title">Dialog title</param>
/// <param name="promptText">Dialog prompt</param>
/// <param name="value">Sets the initial value and returns the result</param>
/// <returns>Dialog result</returns>
public static DialogResult Show(Form parent, string title, string promptText, string checkText, ref string value, ref bool isChecked)
{
// TODO: button placement/size has been hardcoded for how it is used in this app.
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
CheckBox checkBox = new CheckBox();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
textBox.Multiline = true;
textBox.Height = (int)(textBox.Height * 2);
checkBox.Checked = isChecked;
checkBox.Text = checkText;
checkBox.Visible = (checkText != null);
//form.TopLevel = true;
//form.StartPosition = FormStartPosition.CenterParent;
//form.Parent = parent;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 76, 372, 50);
buttonOk.SetBounds(228, 130, 75, 23);
buttonCancel.SetBounds(309, 130, 75, 23);
checkBox.SetBounds(12, 60, 150, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
checkBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
form.ClientSize = new Size(396, 170);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel, checkBox });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
isChecked = checkBox.Checked;
return dialogResult;
}
示例13: Show
/// <summary>
/// Muestra el 'InputTextBox'
/// </summary>
/// <param name="strTexto"> Texto a mostrar en el mensaje </param>
/// <param name="strEncabezado"> Título del InputTextBox </param>
/// <param name="strValor"> Texto ingresado </param>
/// <param name="itbValidacion"> Delegado que valida lo ingresado en el InputTextBox </param>
/// <returns>DialogResult</returns>
public static DialogResult Show(string strTexto, string strEncabezado, ref string strValor, InputBoxValidation itbValidacion)
{
Form frmFormulario = new Form();
Label lblEtiqueta = new Label();
TextBox txtCajaTexto = new TextBox();
Button btnOK = new Button();
Button btnCancel = new Button();
frmFormulario.Text = strEncabezado;
lblEtiqueta.Text = strTexto;
txtCajaTexto.Text = strValor;
btnOK.Text = "OK";
btnCancel.Text = "Cancel";
btnOK.DialogResult = DialogResult.OK;
btnCancel.DialogResult = DialogResult.Cancel;
lblEtiqueta.SetBounds(9, 20, 372, 13);
txtCajaTexto.SetBounds(12, 36, 372, 20);
btnOK.SetBounds(228, 72, 75, 23);
btnCancel.SetBounds(309, 72, 75, 23);
lblEtiqueta.AutoSize = true;
txtCajaTexto.Anchor = txtCajaTexto.Anchor | AnchorStyles.Right;
btnOK.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
btnCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
frmFormulario.ClientSize = new Size(396, 107);
frmFormulario.Controls.AddRange(new Control[] { lblEtiqueta, txtCajaTexto, btnOK, btnCancel });
frmFormulario.ClientSize = new Size(Math.Max(300, lblEtiqueta.Right + 10), frmFormulario.ClientSize.Height);
frmFormulario.FormBorderStyle = FormBorderStyle.FixedDialog;
frmFormulario.StartPosition = FormStartPosition.CenterScreen;
frmFormulario.MinimizeBox = false;
frmFormulario.MaximizeBox = false;
frmFormulario.AcceptButton = btnOK;
frmFormulario.CancelButton = btnCancel;
if (itbValidacion != null)
{
frmFormulario.FormClosing += delegate(object sender, FormClosingEventArgs e)
{
if (frmFormulario.DialogResult == DialogResult.OK)
{
string errorText = itbValidacion(txtCajaTexto.Text);
if (e.Cancel = (errorText != ""))
{
MessageBox.Show(frmFormulario, errorText, "Mensaje",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtCajaTexto.Focus();
}
}
};
}
DialogResult dialogResult = frmFormulario.ShowDialog();
strValor = txtCajaTexto.Text;
return dialogResult;
}
示例14: Show
public static DialogResult Show(IWin32Window owner, string title, string promptText, string promptText2, ref string value, ref string value2)
{
using (Form form = new Form())
{
Label label = new Label();
Label label2 = new Label();
TextBox textBox = new TextBox();
TextBox textBox2 = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
label2.Text = promptText2;
textBox.Text = value;
textBox2.Text = value2;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
label2.SetBounds(9, 66, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
textBox2.SetBounds(12, 82, 372, 20);
buttonOk.SetBounds(228, 118, 75, 23);
buttonCancel.SetBounds(309, 118, 75, 23);
label.AutoSize = true;
label2.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
textBox2.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 153);
form.Controls.AddRange(new Control[] {label, label2, textBox, textBox2, buttonOk, buttonCancel});
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = owner != null ? form.ShowDialog(owner) : form.ShowDialog();
value = textBox.Text;
value2 = textBox2.Text;
return dialogResult;
}
}
示例15: PeopleForm
public PeopleForm(string title=null, IPeopleFormDelegate peopleFormDelegate = null, bool openForUpdate = false,string surname="", string firstname="", string password="", string comment="")
{
if (null != title) this.Text = title;
_openForUpdate = openForUpdate;
_peopleFormDelegate = peopleFormDelegate;
this.SetBounds(10, 10, 200, 220);
Label lbl1, lbl2,lbl3, lbl4;
TextBox txt1, txt2,txt3,txt4;
Button btn = new Button();
this.Controls.Add(lbl1 = new Label());
lbl1.SetBounds(5, 5, 185, 18);
lbl1.Text = "firstname";
this.Controls.Add(txt1 = new TextBox());
txt1.SetBounds(5, 25, 185, 18);
txt1.Text = firstname;
this.Controls.Add(lbl2 = new Label());
lbl2.Text = "surname";
lbl2.SetBounds(5, 45, 185, 18);
this.Controls.Add(txt2 = new TextBox());
txt2.SetBounds(5, 65, 165, 18);
txt2.Text = surname;
this.Controls.Add(lbl3 = new Label());
lbl3.SetBounds(5, 85, 185, 18);
lbl3.Text = "password";
this.Controls.Add(txt3 = new TextBox());
txt3.SetBounds(5, 105, 185, 18);
txt3.Text = password;
this.Controls.Add(lbl4 = new Label());
lbl4.SetBounds(5, 125, 185, 18);
lbl4.Text = "comment";
this.Controls.Add(txt4 = new TextBox());
txt4.SetBounds(5, 145, 185, 18);
txt4.Text = comment;
this.Controls.Add(btn);
btn.SetBounds(5, 165, 185, 18);
ErrorProvider ep = new ErrorProvider();
ep.SetIconAlignment(txt2, ErrorIconAlignment.MiddleRight);
ep.SetIconPadding(txt2, 2);
btn.Text = openForUpdate ? "Save people" : "Add people";
btn.Click += (object sender1, EventArgs e1) =>
{
if (string.IsNullOrWhiteSpace(txt2.Text))
{
ep.SetError(txt2, "Surname must contain chars");
return;
}
ep.SetError(txt2, string.Empty);
if (null != this._peopleFormDelegate) _peopleFormDelegate.saved(txt2.Text, txt1.Text, txt3.Text, txt4.Text);
if(openForUpdate) this.Close();
};
}