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

Define your own dialog box in win form

By , 19 Mar 2012
Rate this:
Please Sign up or sign in to vote.

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 nothing more than a simple man with the high vision of evolving multifaceted software systems by using my technical and interpersonal skills which will complement my professional growth. I feel enjoyment to take challenges to resolve those technical problems which are yet to be solved.
My Blog:
My Email: rashimiiuc at yahoo dot com
Follow on   Twitter

Comments and Discussions

QuestionHello Pinmemberemon.arafat19-Dec-12 11: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    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
Web04 | 2.8.140415.2 | Last Updated 19 Mar 2012
Article Copyright 2012 by Md. Rashim uddin
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid