我想创建一个没有消息框按钮的消息框,没有最小化和最大化按钮,只有一个关闭按钮。我该怎么做?
谢谢。
我很困惑如何创建那个。
答案 0 :(得分:4)
创建表单并将其用作messagebox
。将其MaximizeBox
和MinimizeBox
属性设置为false。并使用ShowDialog()
调用该表单。我希望它可以解决你的问题。
答案 1 :(得分:3)
创建一个名为CustomMsgBox的表单并粘贴以下代码。
public class CustomMsgBox : Form {
private string _msg = string.Empty;
public CustomMsgBox(string msg) {
InitializeComponent();
this.MinimizeBox = false;
this.MaximizeBox = false;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
Button btn = new Button()
btn.Text = "&Close";
btn.Width = 80;
this.Controls.Add(btn);
btn.Location = new Point(this.Width - (btn.Width + 50), this.Height - (btn.Height + 50));
this.CancelButton = btn;
this.AcceptButton = btn;
btn.Click += new EventHandler(this.btn_Clicked);
}
private void btn_Clicked(object sender, EventArgs e)
{
this.Close();
}
}
public class MyMessageBox
{
public static DialogResult Show(string _message)
{
return Show(_message, string.Empty);
}
public static DialogResult Show(string _message, string _title)
{
CustomMsgBox msg =new CustomMsgBox(_message);
msg.Text = _title;
rturn msg.ShowDialog();
}
}
CALL:
MyMessageBox.Show("This is a sample Text 1", "Hello World");
MyMessageBox.Show("This is a sample Text 2");
答案 2 :(得分:1)
只需创建一个新的Form
,其MaximizeBox
和MinimizeBox
属性设置为false
。这将仅在标题栏中保留关闭按钮。
E.g:
public class MyCustomMessageBox : Form {
public string Text { get; set; }
public MyCustomMessageBox() {
MinimizeBox = false;
MaximizeBox = false;
}
}
然后:
var messageBox = new MyCustomMessageBox();
messageBox.ShowDialog();
在表单上创建一个标签,并使用Text
属性填充它。
答案 3 :(得分:0)
只需设置Form属性-> ControlBox = FALSE,即可删除表单具有的Close和Min,Max按钮。