Answer the question
In order to leave comments, you need to log in
C#. How to embed a dialog box in a console application?
Good afternoon!
Can you please tell me how to implement a dialog box in a console application?
Here's what I've got so far:
static void Main(string[] args)
{
Size resolution = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size;
Console.WriteLine(resolution);
if (resolution.Height == 1080 && resolution.Width == 1920)
{
Console.WriteLine("Yes");
Form frmAbout = new Form();
Button button1 = new Button();
Button button2 = new Button();
button1.Text = "Продолжить";
button2.Text = "Завершить программу";
frmAbout.Controls.Add(button1);
frmAbout.ShowDialog();
}
Console.WriteLine("Я сработал");
}
private void button1_Click(object sender, System.EventArgs e)
{
Тут надо закрыть форму и продолжить выполнение программы
}
private void button2_Click(object sender, System.EventArgs e)
{
А тут надо завершить выполнение программы
}
}
Answer the question
In order to leave comments, you need to log in
Most likely, you need to redefine the form and add a delegate and a function that closes the form.
delegate void CloseFormCallback();
private void CloseForm()
{
try
{
if (this.IsDisposed || this.Disposing) return;
CloseFormCallback d = CloseForm;
if (this.InvokeRequired)
{
Invoke(d);
}
else
{
this.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question