Page 1 of 2

Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:45 pm
by SBarnes
Is there a way to limit the number of forms/tabs that a user can open in the MDI Parent?

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:46 pm
by Scott.Pearce
Sound like a job for a plugin.

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:48 pm
by SBarnes
Yeah I know that but not where to start???

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:49 pm
by Scott.Pearce
Code: Select all
Manager.MDIParentForm.MdiChildren

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:50 pm
by Mike.Sheen
SBarnes wrote:Yeah I know that but not where to start???


Manager has a property, MDIParentForm and that has a property OwnedForms which is a list of Form. Use the count of that to see if you have exceeded your imposed limit in a handler of the Manager.FormFactory BeforeFormStart event.

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:51 pm
by Scott.Pearce
You are making it too easy for him Mike ;-)

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:52 pm
by Mike.Sheen
Scott.Pearce wrote:You are making it too easy for him Mike ;-)


Sorry - I didn't realise we were supposed to be making it difficult.

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 4:55 pm
by SBarnes
No if you wanted to make it difficult you would have given me the code in CIL but it's not April yet :lol:

Re: Limit Tabs / Forms

PostPosted: Thu Jan 16, 2020 5:53 pm
by SBarnes
Ah see you promised not to make it difficult and unless I've missed something I found a bug in the below code only the After Start message shows up and looking in Just Decompile in the form Factory BeforeFormStart is declared but never checked for being set and called and OwnedForms.Length is always zero.

Code: Select all
public class ApplicationManagerPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaApplicationManagerPlugin
{
   
    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
      //System.Diagnostics.Debugger.Launch();
      Plugin.Manager.FormFactory.BeforeFormStart += BeforeFormStart;
      Plugin.Manager.FormFactory.AfterFormStart += AfterFormStart;
      
      
    }
   
   
    public void BeforeFormStart(JiwaFinancials.Jiwa.JiwaApplication.Forms.Form form, string RecordID, bool NewRecord, object OwnerForm)
   {
      
      System.Windows.Forms.MessageBox.Show("Before form start " +  form.Manager.MDIParentForm.MdiChildren.Length.ToString());
   }
   
   
   public void AfterFormStart(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm)
   {
        System.Windows.Forms.MessageBox.Show("After form start " +  JiwaForm.Manager.MDIParentForm.MdiChildren.Length.ToString());       
   }
}

Re: Limit Tabs / Forms

PostPosted: Fri Jan 17, 2020 9:06 am
by Mike.Sheen
Ok, then use the property Scott suggested - Manager.MDIParentForm.MdiChildren.

I only suggested OwnedForms because in our LogOff method we use that to close all open forms - whether they are MDI Children or not:

Code: Select all
Public Sub LogOff()
   Dim cancelargs As New System.ComponentModel.CancelEventArgs
   RaiseEvent LoggingOff(cancelargs)

   If cancelargs.Cancel = False Then
      If Not MDIParentForm Is Nothing Then
         For Each form As Form In MDIParentForm.OwnedForms
            form.Close()
         Next
      End If
...