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:
FuliggineBox.ShowQuestion("Sei Allergico al Gatto?");
FuliggineBox.ShowError("Sei Allergico al Gatto.","ATTENTO");
int i= 15;
FuliggineBox.ShowValue(i);
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
{
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
:
- I make a class derived from a
Form
- I put the
propertycontrol
in the "form
" - I add a property called "
Selectedobject
"
namespace Fuliggine.Dialogs.Embedded
{
public class ControlPropertyForm : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid propertyGrid1;
public object Selectedobject
{
get{return this.propertyGrid1.SelectedObject;}
set{this.propertyGrid1.SelectedObject=value;}
}
public ControlPropertyForm()
{
InitializeComponent();
}
#region Windows Forms Designer generated code
}
}
And we will call these Dialogs
as follows:
pf.Selectedobject=this;
pf.Show();
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.
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