Kaoru
Kaoru

Reputation: 2883

Create custom message box with no buttons and no minimize and maximize button

i want to create a message box with no message box buttons and no minimize and maximize button, there just a close button. How do i do that?

Thank you.

I am confuse how to create that one.

Upvotes: 2

Views: 3221

Answers (4)

sachith95
sachith95

Reputation: 13

just set the Form property -> ControlBox = FALSE then it will remove Close and Min,Max buttons that form has.

Upvotes: 0

Raging Bull
Raging Bull

Reputation: 18747

Create a form and use it like a messagebox. Set its MaximizeBox and MinimizeBox properties to false. And invoke that form using ShowDialog(). I hope it would solve your problem.

Upvotes: 4

Shell
Shell

Reputation: 6849

Create a form with name CustomMsgBox and paste following code.

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");

Upvotes: 3

Simon Whitehead
Simon Whitehead

Reputation: 65077

Simply create a new Form with its MaximizeBox and MinimizeBox properties set to false. This will leave the close button only in the title bar.

E.g:

public class MyCustomMessageBox : Form {

    public string Text { get; set; }

    public MyCustomMessageBox() {
        MinimizeBox = false;
        MaximizeBox = false;
    }
}

Then:

var messageBox = new MyCustomMessageBox();
messageBox.ShowDialog();

Create a label on your form and use the Text property to populate it.

Upvotes: 1

Related Questions