public static DialogResult Show(string title, string promptText, out string value) { Form form = new Form(); Label label = new Label(); TextBox textBox = new TextBox(); Button buttonOk = new Button(); Button buttonCancel = new Button();
textBox.UseSystemPasswordChar = true;
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;
DialogResult dialogResult = form.ShowDialog(); value = textBox.Text; return dialogResult; }
using Eto.Drawing;using Eto.Forms;using System;
namespace EtoSample{ public static class PasswordInputBox { public static DialogResult ShowDialog(string title, string promptText, out string value) { var dialog = new Dialog(); dialog.Title = title;
var passwordBox = new PasswordBox();
var buttonOk = new Button { Text = "Ok" }; buttonOk.Click += buttonOk_Click;
var buttonCancel = new Button { Text = "Cancel" };
dialog.DefaultButton = buttonOk; dialog.AbortButton = buttonCancel;
var layout = new DynamicLayout();
layout.BeginVertical(); // fields section layout.AddRow(new Label { Text = promptText }); layout.AddRow(passwordBox); layout.EndVertical();
layout.BeginVertical(); // buttons section // passing null in AddRow () creates a scaled column layout.AddRow(null, buttonOk, buttonCancel); layout.EndVertical();
dialog.Content = layout; dialog.Topmost = true;
var center = Screen.PrimaryScreen().WorkingArea.Center; center.X -= 80; center.Y -= 40;
dialog.Location = new Point(center);
dialog.Visible = true;
var result = dialog.ShowDialog(); value = passwordBox.Text;
return result; }
private static void buttonOk_Click(object sender, System.EventArgs e) { var dialog = (Dialog)((Button)sender).ParentWindow; dialog.Close(DialogResult.Ok); } }}
if (PasswordInputBox.ShowDialog("Numbers", "Input: ", out value) == DialogResult.Ok){ MessageBox.Show(value);}
using Eto.Drawing;using Eto.Forms;using System;
namespace EtoSample{
public class PasswordInputBox : Dialog { public string Text { get; set; }
PasswordBox passwordBox;
public PasswordInputBox(string title, string promptText) { this.Title = title;
this.passwordBox = new PasswordBox();
var buttonOk = new Button { Text = "Ok" }; buttonOk.Click += buttonOk_Click;
var buttonCancel = new Button { Text = "Cancel" };
this.DefaultButton = buttonOk; this.AbortButton = buttonCancel;
var layout = new DynamicLayout();
layout.BeginVertical(); // fields section layout.AddRow(new Label { Text = promptText }); layout.AddRow(passwordBox); layout.EndVertical();
layout.BeginVertical(); // buttons section // passing null in AddRow () creates a scaled column layout.AddRow(null, buttonOk, buttonCancel); layout.EndVertical();
this.Content = layout; this.Topmost = true;
var center = Screen.PrimaryScreen().WorkingArea.Center; center.X -= 80; center.Y -= 40;
this.Location = new Point(center); }
private void buttonOk_Click(object sender, System.EventArgs e) { this.Text = passwordBox.Text; this.Close(DialogResult.Ok); } }}
var pBox1 = new PasswordInputBox("Numbers", "Input: ");
if (pBox1.ShowDialog() == DialogResult.Ok) { MessageBox.Show(pBox1.Text); }
var pBox2 = new PasswordInputBox("Numbers", "Input: ");
if (pBox2.ShowDialog() == DialogResult.Ok) { MessageBox.Show(pBox2.Text); }