开发者

How to set a custom position for a MessageBox

I want to display a MessageBox at a given position. I don't want the MessageBox to overlay and hide a section of the parent form. Is there a way using the default MessageBox object to specify a custom location?

I'm using C# in VS 2008 with .开发者_JAVA技巧Net Framework 3.5


You can not change the attributes of the message box. You will have to create your own form() and use it as a message box. This way you can define everything about it (position, size, etc)

Here's one that I've done.

public partial class NotifyForm : Form
    {
        public NotifyForm(string message, string title)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;// Or wherever 

            lblMessage.Text = "\r\n" + message;
            this.Text =  title;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

And I Initialize it like this:

NotifyForm frm = new NotifyForm("Added item: " + txtAddAcc.Text + " to Accessibility Categories list.", "Add Item!");
frm.Show();


You can create own custom MessageBox from From and show it as DialogBox in this way you can set the startup location. For example:

   var form = new Form
                       {
                           StartPosition = FormStartPosition.Manual, 
                           ShowInTaskbar = false,
                           Location = new Point(100,100)
                       };
        form.ShowDialog();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜