开发者

Add message to popup message box C# noob question

How can I add message to popup text box:

        catch (Exception)
        {
            Interaction.MsgBox(Conversion.ErrorToString(), MsgBoxStyle.Critical, null);
        }
开发者_高级运维


You can use the MessageBox class.

catch (Exception)
{
    MessageBox.Show(
         Conversion.ErrorToString(),  // Caption
         "Error:",                    // Title displayed
         MessageBoxButtons.OK,        // Only show OK button
         MessageBoxIcon.Error);       // Show error icon (similar to Critical)
}


MessageBox.Show("text", "caption", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);

Also, I see you tagged the post C#. If you're using C#, don't use anything in the Microsoft.VisualBasic namespace (which is where Interaction lives)

The Microsoft.VisualBasic namespace contains types that support the Visual Basic Runtime in Visual Basic.


Some more examples:

http://www.dotnetperls.com/messagebox-show


You already are, with Conversion.ErrorToString(). If you want a custom message, just pass a string of your choosing as the first argument instead. The third argument (which you have null), can be used to pass a string for the title if you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜