Click here to Skip to main content
Click here to Skip to main content
Go to top

Define your own dialog box in win form

, 19 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to define your own dialogue box

Say, you have two Forms namely FrmMain and FrmDialog and you want to show up FrmDialog from FrmMain. When you click OK/Yes button then it might return DialogResult and Fill Up some variables data that you need in your FrmMain for further processing. So what should we do in this case? Let’s move forward in Step by step

  1. Design Your FrmMain.cs
  2. Design your FrmDialog.cs as a Dialog Window
    1. from the property window set controlBox=False
    2. Add Two Buttons Ok and Cancel

In the below code, GetData() method opens up the Dialog window. When we Click Okay/Cancel button, it set up DialogResult for current window also fill-up the variable data as well.

private static List<Test> currentList=null;
 
public static bool GetData(ref List<Test> referenceList)
 
{
 
FrmDialog frm = new FrmDialog();
 
if (frm.ShowDialog() == DialogResult.OK)
 
{
 
referenceList = currentList;
 
}
 
this.DialogResult
 
}
 
private void BtnOk_Click(object sender, EventArgs e)
 
{
 
currentList=this.GetData();
 
this.DialogResult = DialogResult.OK;
 
this.Close();
 
}
 
private void BtnCancel_Click(object sender, EventArgs e)
 
{
 
this.DialogResult = DialogResult.Cancel;
 
this.Close();
 
}

Call the GetData() method from FrmMain.cs like the way,

List<Test> currentList=null;
 
if (FrmDialog.GetData (ref currentList)== DialogResult.OK)
 
{
 
////Do Whatever you want
 
}

License

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

Share

About the Author

Md. Rashim uddin
Software Developer (Senior) KAZ Software Limited.
Bangladesh Bangladesh
I am a true visionary as well as have always been passionate about learning. I always love to work with thought-provoking personnel to develop amazing, exciting and innovative ideas as part of an aggressive team that challenges my ingenious ideas, creativeness and extensive experience.
 
My Blog: http://rashimuddin.wordpress.com/
 
My Email: rashimiiuc at yahoo dot com
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionHello Pinmemberemon.arafat19-Dec-12 11:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 19 Mar 2012
Article Copyright 2012 by Md. Rashim uddin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid