Đây là một đơn giản C# mới ứng dụng Windows Forms:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(this, message, caption, buttons);
if (result == DialogResult.Yes)
{
// Closes the parent form.
this.Close();
}
}
}
}
Như Dusty states in his answer, một hộp thông báo là một hộp thoại modal. Chỉ định thuộc tính 'chủ sở hữu'. Trong ví dụ này, chủ sở hữu được biểu thị bằng từ khóa 'this'.
Bạn đang tạo hộp thư trên một chuỗi riêng biệt? – LBushkin
Cả hai đều nằm trong chuỗi riêng biệt. Nó có ảnh hưởng không? – Mahesh
Tôi cũng đã thấy điều này xảy ra. Nó thường là trong một số trường hợp mà không ai có thể nhân đôi. Bạn có thể sao chép nó theo yêu cầu không? –