Click here to Skip to main content
15,886,806 members
Articles / Programming Languages / C#
Article

Fast Dialogs and Message Boxes

Rate me:
Please Sign up or sign in to vote.
2.84/5 (20 votes)
13 Jun 2006CPOL2 min read 24.5K   703   14  
Some useful messageboxes and dialogs
Sample Image - FuliggineDialogs.png

Introduction

How many times have you used the instruction: MessageBox.Show();? Well, this article explains how we can expand this feature of the framework for an immediate use of this function.

The Namespace

First of all, I divide the main namespace in three parts:

Fuliggine.Dialogs.Embedded; Embedded Dialogs like zoom form or find form
Fuliggine.Dialogs.Static; Static Dialogs like message box
Fuliggine.Dialogs.Dinamic; Customizable Dialogs (not yet implemented)

How To Use

First of all, add the using reference:

C#
using Fuliggine;
using Fuliggine.Dialogs.Static;
using Fuliggine.Dialogs.Embedded;

To call a static Dialog, you need:

C#
//Do a question
FuliggineBox.ShowQuestion("Sei Allergico al Gatto?");
//notify error
FuliggineBox.ShowError("Sei Allergico al Gatto.","ATTENTO");
//Show integer
int i= 15;
FuliggineBox.ShowValue(i);
//Show an object or something unknown
FuliggineBox.ShowObject("Comments to print",this);

To see all ways to call those methods, take a look at the source code.
To call an embedded Dialog, you need to:

C#
ZoomForm zf = new ZoomForm();
            
zf.Zoom=28;
            
if(zf.ShowDialog()==DialogResult.OK)
{           
    FuliggineBox.ShowError(zf.Zoom.ToString());
}

Source Code

For the FuliggineBox, I declare a static class where I call the method MessageBox.Show. With this, we can use custom message calling...

C#
FuliggineBox.ShowQuestion("???"); 

...instead of:

C#
MessageBox.Show( Text ,"Question",MessageBoxButtons.YesNo, 
		MessageBoxIcon.Question,MessageBoxDefaultButton.Button1); 
C#
public class FuliggineBox
{    
//
//Fuliggine Question
//
public static DialogResult ShowQuestion(string Text)
{
return
MessageBox.Show( Text ,"Question",MessageBoxButtons.YesNo,
MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
}
//...

For the embedded Dialogs, I use a Form that's equipped with all the needed controls and properties. For example, I show the code for the propertyDialog:

  1. I make a class derived from a Form
  2. I put the propertycontrol in the "form"
  3. I add a property called "Selectedobject"
C#
namespace Fuliggine.Dialogs.Embedded
{
    public class ControlPropertyForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.PropertyGrid propertyGrid1;
        //this property must be set before call(...to show some things)
        public object Selectedobject
        {
            get{return this.propertyGrid1.SelectedObject;}
            set{this.propertyGrid1.SelectedObject=value;}        
        }
        public ControlPropertyForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms 
	   // designer support.
            //
            InitializeComponent();        
        }        
        
        #region Windows Forms Designer generated code       
    }
}

And we will call these Dialogs as follows:

C#
pf.Selectedobject=this;//Or something else...
pf.Show();//Or ShowDialog

At the End...

In the future, I will expand the number of embedded Dialogs adding - Font Dialog -Color Dialog - and every Dialog you need. I will also add the left class Fuliggine.Dialogs.Dinamics.

Framework Problematics

This code is written under Sharp Develop with framework 2. Sharp Develop is fully compatible with Visual Studio 2005, but if you use a different compiler/version of the framework, you only need to add the files in your solution and rebuild all.

Credits

This is only one of the possible solutions. Maybe it isn't the best one, but I think that it is simple and fast. For any advice, question or problem, please contact me. If you would like to see my other work, please visit my home page.

Image 2

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Italy Italy
I'm senior developer and architect specialized on portals, intranets, and others business applications. Particularly interested in Agile developing and open source projects, I worked on some of this as project manager and developer.

My programming experience include:

Frameworks \Technlogies: .NET Framework (C# & VB), ASP.NET, Java, php
Client languages:XML, HTML, CSS, JavaScript, angular.js, jQuery
Platforms:Sharepoint,Liferay, Drupal
Databases: MSSQL, ORACLE, MYSQL, Postgres

Comments and Discussions

 
-- There are no messages in this forum --