Click here to Skip to main content
12,699,898 members (35,793 online)
Click here to Skip to main content
Add your own
alternative version


6 bookmarked

Define your own dialog box in win form

, 19 Mar 2012 CPOL
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;
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 like the 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 12:02
memberemon.arafat19-Dec-12 12:02 
Good Work.It helps.
hi I am Emon. I am new in C# programming.
Please help me to Enter this magical world...........

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 19 Mar 2012
Article Copyright 2012 by Md. Rashim uddin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid