本文整理汇总了C#中Form.ShowDialog方法的典型用法代码示例。如果您正苦于以下问题:C# Form.ShowDialog方法的具体用法?C# Form.ShowDialog怎么用?C# Form.ShowDialog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Form
的用法示例。
在下文中一共展示了Form.ShowDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
internal static void Run()
{
var f = new Form() { Width = 400, Height = 300 };
var b = new Button() { Text = "Run", Dock = DockStyle.Fill, Font = new Font("Consolas", 18) };
f.Controls.Add(b);
b.Click += async delegate
{
b.Text = "... Running ... ";
await Task.WhenAll(WithSyncCtx(), WithoutSyncCtx()); // warm-up
var sw = new Stopwatch();
sw.Restart();
await WithSyncCtx();
var withTime = sw.Elapsed;
sw.Restart();
await WithoutSyncCtx();
var withoutTime = sw.Elapsed;
b.Text = string.Format("With : {0}\nWithout : {1}\n\nDiff : {2:F2}x",
withTime, withoutTime, withTime.TotalSeconds / withoutTime.TotalSeconds);
};
f.ShowDialog();
}
示例2: Draw
public static Rectangle Draw(Pen pen, Form parent)
{
sPen = pen;
// Record the start point
mPos = parent.PointToClient(Control.MousePosition);
// Create a transparent form on top of the parent form
mMask = new Form();
mMask.FormBorderStyle = FormBorderStyle.None;
mMask.BackColor = Color.Magenta;
mMask.TransparencyKey = mMask.BackColor;
mMask.ShowInTaskbar = false;
mMask.StartPosition = FormStartPosition.Manual;
mMask.Size = parent.ClientSize;
mMask.Location = parent.PointToScreen(Point.Empty);
mMask.MouseMove += MouseMove;
mMask.MouseUp += MouseUp;
mMask.Paint += PaintRectangle;
mMask.Load += DoCapture;
// Display the overlay
mMask.ShowDialog(parent);
// Clean-up and calculate return value
mMask.Dispose();
mMask = null;
Point pos = parent.PointToClient(Control.MousePosition);
int x = Math.Min(mPos.X, pos.X);
int y = Math.Min(mPos.Y, pos.Y);
int w = Math.Abs(mPos.X - pos.X);
int h = Math.Abs(mPos.Y - pos.Y);
return new Rectangle(x, y, w, h);
}
示例3: ShowFormButton_Click
void ShowFormButton_Click (object sender, EventArgs e)
{
Form f = new Form ();
f.Location = new Point (200, 250);
f.StartPosition = FormStartPosition.Manual;
f.Text = "Modal - bug #80784";
f.ShowDialog ();
}
示例4: Advanced_Click
private void Advanced_Click(object sender, EventArgs e)
{
//Set up a form to display the advanced connection properties
Form frm = new Form();
PropertyGrid pg = new PropertyGrid();
pg.SelectedObject = cp;
pg.Dock = DockStyle.Fill;
pg.Parent = frm;
frm.ShowDialog();
}
示例5: ShowDialog
public static Point ShowDialog()
{
if (!_warningShown)
{
MessageBox.Show(@"for double use 1,04 format!");
_warningShown = true;
}
Form prompt = new Form()
{
Width = 280,
Height = 220,
FormBorderStyle = FormBorderStyle.FixedDialog,
Text = @"Enter 3D coordinates",
StartPosition = FormStartPosition.CenterScreen
};
Label XtextLabel = new Label() {Left = 80, Top = 20, Text = "X"};
TextBox XtextBox = new TextBox() {Left = 80, Top = 35, Width = 60};
Label YtextLabel = new Label() {Left = 80, Top = 55, Text = "Y"};
TextBox YtextBox = new TextBox() {Left = 80, Top = 70, Width = 60};
Label ZtextLabel = new Label() {Left = 80, Top = 95, Text = "Z"};
TextBox ZtextBox = new TextBox() {Left = 80, Top = 110, Width = 60};
ZtextBox.Text = "0";
ZtextBox.BackColor = Color.Gray;
Button confirmation = new Button() {Text = "Ok", Left = 80, Width = 80, Top = 140, DialogResult = DialogResult.OK};
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(XtextBox);
prompt.Controls.Add(XtextLabel);
prompt.Controls.Add(YtextBox);
prompt.Controls.Add(YtextLabel);
prompt.Controls.Add(ZtextBox);
prompt.Controls.Add(ZtextLabel);
prompt.Controls.Add(confirmation);
prompt.AcceptButton = confirmation;
if (prompt.ShowDialog() == DialogResult.OK)
{
double x = double.Parse(XtextBox.Text);
double y = double.Parse(YtextBox.Text);
double z = double.Parse(ZtextBox.Text);
return new Point(x, y, z);
}
// недостижимый код
return new Point();
}
示例6: 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 button = new Button();
Button button1 = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
button.Text = "OK";
button1.Text = "Cancel";
button.DialogResult = DialogResult.OK;
button1.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
button.SetBounds(228, 72, 75, 23);
button1.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
button.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
Control.ControlCollection controls = form.Controls;
Control[] controlArray = new Control[] { label, textBox, button, button1 };
controls.AddRange(controlArray);
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 = button;
form.CancelButton = button1;
if (validation != null)
{
form.FormClosing += new FormClosingEventHandler((object sender, FormClosingEventArgs e) => {
if (form.DialogResult == DialogResult.OK)
{
string text = validation(textBox.Text);
bool flag = text != "";
bool flag1 = flag;
e.Cancel = flag;
if (flag1)
{
MessageBox.Show(form, text, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
textBox.Focus();
}
}
});
}
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
示例7: 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;
}
示例8: MainForm_Load
void MainForm_Load (object sender, EventArgs e)
{
Console.WriteLine ("Visible: " + this.Visible.ToString ());
InstructionsForm instructionsForm = new InstructionsForm ();
instructionsForm.Show ();
Form f = new Form ();
f.Location = new Point (200, 100);
f.StartPosition = FormStartPosition.Manual;
f.Text = "Modal - bug #80604";
f.ShowDialog (this);
}
示例9: ShowDialog
public static string ShowDialog(string text, string caption)
{
var prompt = new Form();
prompt.Width = 500;
prompt.Height = 100;
prompt.Text = caption;
var textLabel = new Label() { Left = 50, Top = 20, Text = text };
var textBox = new TextBox() { Left = 50, Top = 50, Width = 400 };
var confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70 };
confirmation.Click += (sender, e) => prompt.Close();
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.Controls.Add(textBox);
prompt.ShowDialog();
return textBox.Text;
}
示例10: Main
public static int Main()
{
Form fm = new Form();
Button btn = new Button();
btn.Location = new System.Drawing.Point(150, 50);
TextBox tb = new TextBox();
tb.Text = "Hello, world";
tb.Location = new System.Drawing.Point(fm.Width/2, fm.Height/2);
btn.Text = "Click";
Label lb = new Label();
lb.Text = Convert.ToString("This is label");
btn.DialogResult = DialogResult.OK;
fm.BackColor = System.Drawing.Color.DarkGreen;
fm.Controls.Add(btn);
fm.Controls.Add(tb);
fm.Controls.Add(lb);
fm.ShowDialog();
return 0;
}
示例11: ShowDialog
public static string ShowDialog(string caption, string text)
{
Form prompt = new Form();
prompt.Width = 500;
prompt.Height = 150;
prompt.FormBorderStyle = FormBorderStyle.FixedDialog;
prompt.Text = caption;
prompt.StartPosition = FormStartPosition.CenterScreen;
Label textLabel = new Label() { Left = 50, Top=20, Text=text };
TextBox textBox = new TextBox() { Left = 50, Top=50, Width=400 };
Button confirmation = new Button() { Text = "Ok", Left=350, Width=100, Top=70, DialogResult = DialogResult.OK };
confirmation.Click += (sender, e) => { prompt.Close(); };
prompt.Controls.Add(textBox);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}
示例12: InputBox
public static DialogResult InputBox(string title, string promptText, ref string value)
{
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;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
示例13: Main
static void Main ()
{
Form form = new Form ();
form.ShowInTaskbar = false;
TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
tableLayoutPanel.ColumnCount = 3;
tableLayoutPanel.Dock = DockStyle.Fill;
tableLayoutPanel.RowCount = 11;
form.Controls.Add (tableLayoutPanel);
Timer timer = new Timer ();
timer.Interval = 100;
timer.Tick += delegate (object sender, EventArgs e) {
form.Close ();
};
form.Load += delegate (object sender, EventArgs e) {
timer.Enabled = true;
};
form.ShowDialog ();
}
示例14: Main
static void Main ()
{
string [] images = new string [] {
"bluearrow.gif",
//"ProductIcon.ico",
"folder.bmp",
"ImageNotAvailable.jpg",
"LunaticsInc.png" };
InstructionsForm instructionsForm = new InstructionsForm ();
instructionsForm.Show ();
string dir = AppDomain.CurrentDomain.BaseDirectory;
foreach (string file in images) {
Form form = new Form ();
form.ClientSize = new Size (300, 300);
form.Location = new Point (250, 100);
form.StartPosition = FormStartPosition.Manual;
form.Text = "bug #335739";
PictureBox pictureBox = new PictureBox ();
pictureBox.BackColor = System.Drawing.Color.White;
pictureBox.Dock = DockStyle.Fill;
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
form.Controls.Add (pictureBox);
string imageFile = Path.Combine (dir, file);
FileStream fs = File.OpenRead (imageFile);
Image img = Image.FromStream (fs, true);
pictureBox.Image = img;
fs.Close ();
form.ShowDialog ();
}
}
示例15: Run
public void Run(string FileName)
{
try
{
m_DataManager.Open(FileName);
m_DataManager.BeginTransaction();
}
catch (Exception ex)
{
ShowException(ex);
return;
}
//Создание главного окна
MyForm = new Form();
MyForm.Width = 400;
MyForm.Height = 400;
MyForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
MyForm.StartPosition = FormStartPosition.CenterScreen;
MyForm.Text = "My SQL Console"; //Заголовок окна
MyForm.FormClosing += OnClose; //Метод OnClick - обработчки события закрытия формы
//Текстовое поле для ввода SQL
SQLText = new TextBox();
SQLText.Width = 296;
SQLText.Height = 200;
SQLText.Multiline = true; //Включение многострочного режима
SQLText.ScrollBars = ScrollBars.Vertical; //Включение вертикальной прокрутки
SQLText.TextChanged += SQLChanged; //Метод SQLChanged - обработчки события изменения текста
//Кнопка запуска SQL
RunSQL = new Button();
RunSQL.Width = 96;
RunSQL.Height = 48;
RunSQL.Text = "Выполнить SQL";
RunSQL.Enabled = false;
RunSQL.Click += RunSQLClick; //Метод RunSQLClick - обработчки события нажатия на кнопку 'Выполнить SQL'
//Кнопка завершения работы
CloseForm = new Button();
CloseForm.Width = 96;
CloseForm.Height = 48;
CloseForm.Text = "Завершить работу";
CloseForm.Click += CloseFormClick; //Метод CloseFormClick - обработчки события нажатия на кнопку 'Завершить работу'
//Список с результатом запроса
DataList = new ListView();
DataList.Width = 394;
DataList.Height = 170;
DataList.View = View.Details; //Включение отображения колонок в списке
DataList.GridLines = true; //Показывать горизонтальные линии в списке
//Добавление созданных элементов на главное окно
//и их размещение в точках (X,Y) = (Left, Top)
MyForm.Controls.Add(SQLText);
SQLText.Left = 0;
SQLText.Top = 0;
MyForm.Controls.Add(RunSQL);
RunSQL.Left = 298;
RunSQL.Top = 0;
MyForm.Controls.Add(CloseForm);
CloseForm.Left = 298;
CloseForm.Top = 50;
MyForm.Controls.Add(DataList);
DataList.Left = 0;
DataList.Top = 202;
//Открытие главного окна в модальном режиме
MyForm.ShowDialog();
}