Click here to Skip to main content
Click here to Skip to main content

Fast Dialogs and Message Boxes

, 13 Jun 2006
Rate this:
Please Sign up or sign in to vote.
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:

using Fuliggine;
using Fuliggine.Dialogs.Static;
using Fuliggine.Dialogs.Embedded;

To call a static Dialog, you need:

//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:

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...

FuliggineBox.ShowQuestion("???"); 

...instead of:

MessageBox.Show( Text ,"Question",MessageBoxButtons.YesNo, 
		MessageBoxIcon.Question,MessageBoxDefaultButton.Button1); 
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"
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:

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.

License

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

About the Author

No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 14 Jun 2006
Article Copyright 2006 by Sir Zeppa'Man
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid