Click here to Skip to main content
13,597,791 members
Click here to Skip to main content
Add your own
alternative version


6 bookmarked
Posted 16 Mar 2012
Licenced CPOL

Define Your Own Dialog Box in Winform

, 19 Mar 2012
Rate this:
Please Sign up or sign in to vote.
How to define your own dialog 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 a step by step manner.

  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 sets 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;
private void BtnOk_Click(object sender, EventArgs e)
this.DialogResult = DialogResult.OK;
private void BtnCancel_Click(object sender, EventArgs e)
this.DialogResult = DialogResult.Cancel;

Call the GetData() method from FrmMain.cs in this way:

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


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


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:

My Email: rashimiiuc at yahoo dot com

You may also be interested in...


Comments and Discussions

QuestionHello Pin
emon.arafat19-Dec-12 11:02
memberemon.arafat19-Dec-12 11:02 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180621.3 | Last Updated 19 Mar 2012
Article Copyright 2012 by Md. Rashim uddin
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid