Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

From ShowModal to Show

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
Avatar of chrisbray
chrisbray
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Peter Kiers

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of x77
x77
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. Peter
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.