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?
 
Gururaj BadamConnect With a Mentor Commented:
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
 
YiogiConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.