Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

From ShowModal to Show

Posted on 2011-09-16
5
Medium Priority
?
319 Views
Last Modified: 2013-12-17
HI,

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.rtbContent.Clear();
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);
myItem.SubItems.Add(frmNote.rtbContent.Text);
myItem.SubItems.Add(frmNote.lblCreation.Text);
}
}

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
0
Comment
Question by:peterkiers
[X]
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
5 Comments
 
LVL 3

Expert Comment

by:chrisbray
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.rtbContent.Clear();
    frmNote.lblCreation.Text = (DateTime.Now.ToString());
    frmNote.MdiParent = this;
    frmNote.Show();
}

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
0
 
LVL 1

Author Comment

by:peterkiers
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.

Peter
0
 
LVL 15

Accepted Solution

by:
x77 earned 2000 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);
    f.Show();
}

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

Open in new window

0
 
LVL 1

Author Comment

by:peterkiers
ID: 36551403
Thanks. Peter
0
 
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 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