Click or drag to resize

GTPUMessageBox

Overview

GTPUMessageBoxis the message box control to be used by FlexPendant applications. You should not use the standard .NET MessageBox.

Design issues

The GTPUMessageBox.Show arguments include an owner argument, which is the control that displays the MessageBox , and a callback, which is a MessageBoxEventHandler called when the MessageBox is closed. Except this, it is used in the same way as the regular Windows MessageBox. It is used together with the regular Windows MessageBoxButtons and MessageBoxIcon.

Simple code example

The following screenshot and code show how to display a simple message on the FlexPendant using the GTPUMessageBox. .

messagebox 1
            string message = "You did not enter a server name. Cancel this operation?";
            string caption = "No Server Name Specified";
            GTPUMessageBox.Show(this, null, message, caption, System.Windows.Forms.MessageBoxIcon.Question, System.Windows.Forms.MessageBoxButtons.YesNo);
          
Note Note

Sometimes it can be a bit tricky to get the first argument right. The owner might be this, this.Parent or even this.Parent.Parent.

Using a callback

The logics in your program determines if there is any need for a callback. In the previous example the callback argument was null.The message box will close down after the user has answered the question, no matter if the answer is Yes or No.

If we think about the message, it seems likely however, that something should happen if you click No. Let us change the implementation and use a callback for this purpose:

            GTPUMessageBox.Show(this, new MessageBoxEventHandler(OnServerMessageClosed), message, caption, System.Windows.Forms.MessageBoxIcon.Question, System.Windows.Forms.MessageBoxButtons.YesNo);
            //implement callback
            private void OnServerMessageClosed(object sender, ABB.Robotics.Tps.Windows.Forms.MessageBoxEventArgs e)
            {
            if(e.DialogResult == System.Windows.Forms.DialogResult.No)
            {
            //Use default server...
            }
            }
          

If we really do not want to take action depending on how the user responds, it makes more sense to use OK instead of Yes and No as message box buttons, e.g:

GTPUMessageBox.Show(this, null, "You are not allowed to perform this operation, talk to your system administrator if you need access", "User Authorization System", MessageBoxIcon.Hand, MessageBoxButtons.OK);

Note Note

The last example uses a better message box title then the previous ones. The title preferably should tell you from which part of the system the message originates.