Need to open many version of my own message box

I have a message box dialog I created so that it can be non-modal.  But I need to open an unknown number of these dialogs.

What's the best way to manage many of the same type of dialog?  An ArrayList of them?

And when I create an event for the dialog closing, how do I know which one to delete from the list?

thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YiogiCommented:
Each of your dialogs is unique. On your dialog closing all you need to do is cast the sender to your dialog type and you will have the dialog you need to delete from your list. I'd suggest a LIst<YourCustomDialog> though since you don't have any fixed size.
0
newbiewebSr. Software EngineerAuthor Commented:
what part is not fixed?  The number of items?  It's never be more than three probably.

Would an ArrayList work??
0
YiogiCommented:
Yes it would. You can add any kind of object to it. But since you are only adding custom controls you created again I'd prefer a List<>. But it's your choise what to implement.
0
Gururaj BadamCommented:
If you add them to ArrayList it will be difficult to get the right one from the list.

You can instead add them to HashTable like this

HashTable ht = new HashTable();
CustomMessageDialog cmd1 = new CustomMessageDialog( "Error Message 1" );
CustomMessageDialog cmd2 = new CustomMessageDialog( "Error Message 2" );
ht.Add( cmd1.GetHashCode(), cmd1 );
ht.Add( cmd2.GetHashCode(), cmd2 );

In the Closing event you can easily get the control reference by

private void CustomMessageDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
   CustomMessageDialog cmd = (CustomMessageDialog) sender;
   ht.Remove( cmd.GetHashCode() );
}


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.