Don't Launch a form if already opened

I am launching a form on a button click. I want to check first and see if the form is already open and if it is open I want to display a message telling them it is already open. Any ideas on how to do this. Here is my code for launching the form.

LaunchFormOptions lfo = new LaunchFormOptions();
		System.Collections.Generic.Dictionary<string, string> mylist = new System.Collections.Generic.Dictionary<string, string>();
		mylist.Add("custid", epiTextQS_CustID.Text.ToString()); 
		mylist.Add("quantity", epiNumericQS_Qty.Text.ToString()); 
		mylist.Add("partnum", epiTextQS_PartNum.Text.ToString()); 
		mylist.Add("numofcolors", epiNumericQS_NumColors.Text.ToString()); 
		mylist.Add("quantitybreaks", epiNumericQtyBreaks.Text.ToString()); 
		mylist.Add("prevorderline", tbLineNumforQuote.Text.ToString()); 
		mylist.Add("prevorder", tbOrderNumforQuote.Text.ToString());
		{if(cbExcludePlusColor.Checked)
					{
		mylist.Add("excludepluscolor", "true");
					}	
				else
				{
			mylist.Add("excludepluscolor", "false");
				}
		}		
		mylist.Add("enflow", tbQuoteAttachments1.Text.ToString()); 
		mylist.Add("enflow2", tbQuoteAttachments2.Text.ToString()); 
		mylist.Add("enflow3", tbQuoteAttachments3.Text.ToString()); 
		mylist.Add("enflow4", tbQuoteAttachments4.Text.ToString()); 
		mylist.Add("actiontype", "NewQuote"); 
		mylist.Add("formtitle", "Quote Configurator Session 1");
		mylist.Add("entitynum", "0");
		string valuein = "Quote";
		lfo.ValueIn = valuein;
		lfo.ContextValue = mylist;
		ProcessCaller.LaunchForm(oTrans, "SMCM001", lfo); 

Interesting. I’ve never done this but here’s a way to see all the forms in the current application:

	private void epiButtonC1_Click(object sender, System.EventArgs args)
	{
        // ** Place Event Handling Code Here **
        var sb = new System.Text.StringBuilder();
        
        foreach(var myform in Application.OpenForms)
        {
            sb.AppendLine(string.Format("Form:{0}",myform.GetType()));
        }
        MessageBox.Show(sb.ToString());
	}

Hope this helps,
Tanner

I think this will help but I am getting this error.
Error: CS0103 - line 2994 (10931) - The name ‘myform’ does not exist in the current context

Strange. I just wrote some similar code and got similar results (see below). I wonder if maybe you are referencing the variable outside of the loop… Try replacing lines 2991-2996 with the code below

        var sb = new System.Text.StringBuilder();
        foreach(Form myf in Application.OpenForms)
        {
            sb.AppendLine(string.Format("Text:{0} Name:{1}",myf.Text,myf.Name));
        }
        MessageBox.Show(sb.ToString());
        return;

Try removing the semicolon on line 2992.

2 Likes

And try removing the semi-colon on 2992.

Edit: @andrew.johnson got there first!

Oh I see that now… definitely the semicolon is the issue!

Thanks

Tanner Post