?
Solved

How to do my own MessageBox in c#

Posted on 2011-09-19
7
Medium Priority
?
317 Views
Last Modified: 2013-12-17
hello,
I try to do my own and display MessageBox when called, I have already created the form.
Someone has an idea
thank you in advance
0
Comment
Question by:abgconsulting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 668 total points
ID: 36560822
Use ShowDialog() on an instance of the form.

eg.

x.ShowDialog();
0
 
LVL 13

Accepted Solution

by:
Naman Goel earned 332 total points
ID: 36560912
0
 
LVL 40
ID: 36560946
What are the features that are not in the standard MessageBox and that you want to have in yours?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 668 total points
ID: 36560949
From the question.
I have already created the form.

All is required is then a ShowDialog so it shows and blocks the form displaying it from working until the custom message box is closed.
0
 

Author Comment

by:abgconsulting
ID: 36560972
Thks
i have found the solution
my solution is in below
public static bool Show(string content, string title, MessageBoxButtons button, MessageBoxIcon icon)
        {
            CustomMessageBox customMessageBox = new CustomMessageBox();
            customMessageBox.lblTitle.Text = title;
            customMessageBox.lbMessage.Text = content;
            customMessageBox.ShowDialog();
      
            return false;
        }

Open in new window

CustomMessageBox.Show("print PDF fails: \n" + ex.Message, "Print PFD",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);

Open in new window

0
 
LVL 13

Expert Comment

by:Naman Goel
ID: 36561071
Here is sample code for you :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class MyMessageBox : Form
    {
        private Panel panel1;
        private Button btnOK;
        private Label lblText;
        private PictureBox picBoxIcon;
        private FlowLayoutPanel flowLayoutPanel1;
        private Panel panelText;
        private TableLayoutPanel tableLayoutPanel1;
    
        public MyMessageBox()
        {
            InitializeComponent();
        }

        public static void ShowMessageBox(Image icon, string message, string title)
        {
            MyMessageBox myMessage = new MyMessageBox();
            if (icon != null)
            {
                myMessage.picBoxIcon.Image = icon;
            }
            myMessage.lblText.Text = message;
            myMessage.Text = title;
            myMessage.ShowDialog();
        }

        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.btnOK = new System.Windows.Forms.Button();
            this.lblText = new System.Windows.Forms.Label();
            this.picBoxIcon = new System.Windows.Forms.PictureBox();
            this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
            this.panelText = new System.Windows.Forms.Panel();
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.picBoxIcon)).BeginInit();
            this.flowLayoutPanel1.SuspendLayout();
            this.panelText.SuspendLayout();
            this.tableLayoutPanel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.btnOK);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(3, 124);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(482, 37);
            this.panel1.TabIndex = 2;
            // 
            // btnOK
            // 
            this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnOK.Location = new System.Drawing.Point(216, 8);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new System.Drawing.Size(75, 23);
            this.btnOK.TabIndex = 0;
            this.btnOK.Text = "OK";
            this.btnOK.UseVisualStyleBackColor = true;
            // 
            // lblText
            // 
            this.lblText.AutoSize = true;
            this.lblText.Location = new System.Drawing.Point(12, 24);
            this.lblText.Name = "lblText";
            this.lblText.Size = new System.Drawing.Size(0, 13);
            this.lblText.TabIndex = 0;
            // 
            // picBoxIcon
            // 
            this.picBoxIcon.Location = new System.Drawing.Point(3, 3);
            this.picBoxIcon.Name = "picBoxIcon";
            this.picBoxIcon.Size = new System.Drawing.Size(100, 109);
            this.picBoxIcon.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.picBoxIcon.TabIndex = 0;
            this.picBoxIcon.TabStop = false;
            // 
            // flowLayoutPanel1
            // 
            this.flowLayoutPanel1.Controls.Add(this.picBoxIcon);
            this.flowLayoutPanel1.Controls.Add(this.panelText);
            this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 3);
            this.flowLayoutPanel1.Name = "flowLayoutPanel1";
            this.flowLayoutPanel1.Size = new System.Drawing.Size(482, 115);
            this.flowLayoutPanel1.TabIndex = 1;
            // 
            // panelText
            // 
            this.panelText.Controls.Add(this.lblText);
            this.panelText.Location = new System.Drawing.Point(109, 3);
            this.panelText.Name = "panelText";
            this.panelText.Size = new System.Drawing.Size(364, 109);
            this.panelText.TabIndex = 1;
            // 
            // tableLayoutPanel1
            // 
            this.tableLayoutPanel1.ColumnCount = 1;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 1);
            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 2;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 73.86364F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 26.13636F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(488, 164);
            this.tableLayoutPanel1.TabIndex = 1;
            // 
            // MyMessageBox
            // 
            this.ClientSize = new System.Drawing.Size(488, 164);
            this.Controls.Add(this.tableLayoutPanel1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "MyMessageBox";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.picBoxIcon)).EndInit();
            this.flowLayoutPanel1.ResumeLayout(false);
            this.flowLayoutPanel1.PerformLayout();
            this.panelText.ResumeLayout(false);
            this.panelText.PerformLayout();
            this.tableLayoutPanel1.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}

Open in new window



you can call your messagebox like this :

MyMessageBox.ShowMessageBox(null, "Hello dear", "Message");
0
 

Author Comment

by:abgconsulting
ID: 36561275
thanks naman_goel !!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question