Wednesday, 20 August 2014

Message Box Class - Confirm,Error, Warning and Info - C#

Leave a Comment
A C# Snippet for creating Message Box with various type of message (Confirm,Error, Warning and Info).

Message Box Class

 
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace messageBox
{
    public static class MsgBox
    {

        // Displays a Confirm type message box    
        // parameter name="sMsg" is The message you want to display
        public static bool Confirm(string sMsg)
        {
            return Confirm("Confirm :", sMsg);
        }
        public static bool Confirm(string sTitle, string sMsg)
        {
            DialogResult ret = MessageBox.Show(sMsg, sTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            return (ret == DialogResult.Yes);
        }

        //---------------------------------------------------------------------
        // Displays a Error type message box      
        // parameter name="sMsg" is The message you want to display
        public static void Error(string sMsg)
        {
            Error("Error :", sMsg);
        }
        public static void Error(string sTitle, string sMsg)
        {
            MessageBox.Show(sMsg, sTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        //---------------------------------------------------------------------
        // Displays a Warning type message box      
        // parameter name="sMsg" is The message you want to display
        public static void Warning(string sMsg)
        {
            Warning("", sMsg);
        }

        //---------------------------------------------------------------------

        // Displays a Warning type message box       
        // parameter name="sCaption" is  Name of Application or Class or Method
        // parameter name="sMsg" is The message you want to display
        public static void Warning(string sCaption, string sMsg)
        {
            if (sCaption.Length == 0)
                sCaption = "Warning";
            MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        //---------------------------------------------------------------------
        // Displays a Information type message box       
        // parameter name="sMsg" is The message you want to display
        public static void Info(string sMsg)
        {
            Info("", sMsg);
        }

        //---------------------------------------------------------------------
        // Displays a Information type message box      
        // parameter name="sCaption" is Name of Application or Class or Method
        // parameter name="sMsg" is The message you want to display
        public static void Info(string sCaption, string sMsg)
        {
            if (sCaption.Length == 0)
                sCaption = "Information";
            MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.