From ShowModal to Show

Posted on 2011-09-16
Last Modified: 2013-12-17

I have a main form called MainForm and a second form called StickyNotes.
On the main form I have just one toolbar-button to call for the form StickyNotes.
It looks like this:

private void tbNewNote_Click(object sender, EventArgs e)
frmNote.txtCaption.Text = "";
frmNote.lblCreation.Text = (DateTime.Now.ToString());
if (frmNote.ShowDialog() == System.Windows.Forms.DialogResult.OK) <=========================
ListViewItem myItem = new ListViewItem(frmNote.txtCaption.Text, 0);
myItem = lvNotes.Items.Add(myItem);

But now I don't want to use a ShowDialog anymore but use multilpe forms
of the StickyNotes.What do I have to change in the code above to achieve this.

Who knows the answer and is willing to help me?

Greetings, Peter Kiers
Question by:peterkiers
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 36551272
Hi Peter,

It sounds as though you want to go to MDI (Multiple Document Interface), meaning that you have multiple child forms for a single parent form.

To do this, set the IsMdiContainer property of the main form to True.

Then change your code as follows:

private void tbNewNote_Click(object sender, EventArgs e)
    frmNote.txtCaption.Text = "";
    frmNote.lblCreation.Text = (DateTime.Now.ToString());
    frmNote.MdiParent = this;

Open in new window

However, unless you are going to ShowDialog you cannot wait for something to occur before you do something.  You will therefore need to move your save code into frmNote.

Once you have done this you will be able to create multiple notes at once.

Chris Bray

Author Comment

ID: 36551321
Hi, thanks for the reaction but I don't use MDI. Its just the mainform with a button
and by pressing on that button another form shows up called the StickyNotes.cs.

LVL 15

Accepted Solution

x77 earned 500 total points
ID: 36551332
You need suscribe FormClosed event for your new form.

Then you can cast Sender when StickyNotes is closed.
private void Button1_Click(object sender, EventArgs e)
    StickyNotes f = new StickyNotes();
    f.FormClosed += new FormClosedEventHandler(this.child_FormClosed);

private void child_FormClosed(object sender, FormClosedEventArgs e)
    Debug.Print(((StickyNotes) sender).Name);

Open in new window


Author Comment

ID: 36551403
Thanks. Peter
LVL 40
ID: 36551414
ShowDialog is a special command that you use in special occasions, since it freezes the code for as long as the form is visible.

Use Show instead.

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question