Hello,
I'm working on a chat application where i need to open seperate Forms for private chat with each user.
For Each New form I saw a Seperate instance in Task Manager, timg_msft suggest me a solution like this:
Form1 frm1 = new Form1();
string myText = this.Text;
this.Text = string.Empty;
frm1.ShowDialog();
this.Text = myText;
in Post: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=703794&SiteID=1
problem with the above code is that I dont want to show it as a Modal form with ShowDialog() because I need to keep them open:
Taking help from this code, I wrote 2 classes here is the code:
public
static class OpenedFormCollection{
private static Dictionary<string, FormCommSuiteMobileBase> openedFormsDictionary = new Dictionary<string,FormCommSuiteMobileBase>(10); public static void UpdateFormsText(string uniqueID){
Dictionary<string, FormCommSuiteMobileBase>.ValueCollection openedForms = openedFormsDictionary.Values; foreach(FormCommSuiteMobileBase form in openedForms){
if(form.UniqueID != uniqueID){
form.Text =
"";}
}
}
public static void AddForm(FormCommSuiteMobileBase formToBeAdded){
if(!openedFormsDictionary.ContainsKey(formToBeAdded.UniqueID)){
openedFormsDictionary.Add(formToBeAdded.UniqueID,formToBeAdded);
}
}
public static void RemoveForm(string uniqueID){
openedFormsDictionary.Remove(uniqueID);
}
}
This class keeps reference to all opened forms and then when new Form is on Top (Activated) it puts all other forms Text proerty to Empty String so showing only one form in Task Manager.
Here is another class from which each of my Application's forms are inherited so that they can participate and understand the behaviour:
public
partial class FormCommSuiteMobileBase : Form{
private string uniqueId; public FormCommSuiteMobileBase(){
InitializeComponent();
this.uniqueId = Guid.NewGuid().ToString();}
public string UniqueID{
get { return this.uniqueId; } set { this.uniqueId = value; }}
private void FormCommSuiteMobileBase_Load(object sender, EventArgs e){
OpenedFormCollection.AddForm(this);}
private void FormCommSuiteMobileBase_Activated(object sender, EventArgs e){
this.Text = "Application Name"; OpenedFormCollection.UpdateFormsText(this.uniqueId);}
private void FormCommSuiteMobileBase_Closed(object sender, EventArgs e){
OpenedFormCollection.RemoveForm(this.uniqueId);}
}
Each from inherited from the above class will put a reference to OpenedFormCollection from Load Event and removes itself from it when it is Closed.....
In Activated event it sets its Text and removes text from all other forms...
So at a single time even if there are 10 Forms are open only one is shown in the Task Manager, Now the problem arises when a user Selects the Program from Task Manager and Stop it, Suppose the currently opened form is a Secondary Form not the Main, even it is closed The application is not stopped and the other find which is under it becomes visible and Task Manager starts showing the new one!!!
I want to know How to close all the opened forms of the Application when a Stop button is pressed from the Task Manager
Second Problem is that, I want to provide a unified Menu in all the Form for switching to other forms like MSN Messenger for Pocket PC,
Chats -> Rizwan, John, Karin (All Chatters with which Currently Chatting).
Is there a way possible to use or update the same menu items on all the Opened Forms I tried to put this Menu in the BaseForm but it doesnot show up in the Inherited forms even putting Menu to Public... On the other hand if I used ToolBar in the BaseForm its shown on all Forms
Any help in this problem will be highly appreciated from heart!
Best Regards,

Opening So many Forms & Task Manager!!!
Can-Ann
Ahhhh! I got it, I was thinking it in Wrong Sense!!!
For this to Work Perfect I need to Set MinimizeBox property of OpenedFormCollection to true!
Thanks you so much...
What about Menu Problem I'm using .Net 2.0 on Windows Mobile 2005...
Can you explain a bit. Should I make the Menu to be Private How to Add MenuItems and respective event Hadlers on all the Forms
Best Regards,
HedleySohn
"Hook up into the Closing event of your main form (the one that was used in the Application.Run) and clean up all of the openned forms."
You did not get my point, That's ok I can close forms when Main Form is closed! What if Task Manager is showing a Secondary form at a specific time because it is active and when Click Stop Button on that Instance, Application is still running, Because Primary froms and all other forms are still running, Above is closed and one other pops up at its place....
I hope you understand what I mean, If not Please, Please try my code in a sample application and see what happens.
I really appreciate your concern!
Best Regards,
dic_brookes
>I want to know How to close all the opened forms of the Application when a Stop button is pressed from the Task Manager
Hook up into the Closing event of your main form (the one that was used in the Application.Run) and clean up all of the openned forms.
>Is there a way possible to use or update the same menu items on all the Opened Forms I tried to put this Menu in the BaseForm but it doesnot show up >in the Inherited forms even putting Menu to Public... On the other hand if I used ToolBar in the BaseForm its shown on all Forms
It should work. Worked for me. What OS/CF version are you running
-Alex
AsifHameed1