locked
problem resizing inherited form RRS feed

  • General discussion

  • Hi

    I have windows a base form called FormBase which I use to inherit from it child forms. I use a parent form say (Form1: FormBase) inheriting FormBase to open a child form say (Form2:FormBase) which is also inheriting the same FormBase. The problem I’m having is the following. If Form1 (parent) is maximized when open the child form (Form2) with its windowsState is set to normal the parent Form gets minimized. Is there a way to separate the behaviour of the child form from the parent form even though they are inheriting from the same FormBase

    Thanks for your help in advance


    • Moved by CoolDadTx Wednesday, June 13, 2012 1:56 PM Winforms related (From:Visual C# General)
    • Edited by msdnNas Thursday, June 21, 2012 6:43 PM
    • Changed type Bob Wu-MT Friday, June 29, 2012 2:21 AM third party related
    Monday, June 11, 2012 4:26 AM

All replies

  • If I understand you correctly,

    FormBase is the baseClass with several members (WindowState is one of them).

    Form1 and Form2  derive from FormBase

    from within Form1 you create the Object for Form2. And, when you set WindowState property of Form1 to Maximize your Child Form (Form2) also

    maximizes. If this is what your Problem is, then one way to achieve solution is:

    If WindowState is a property coming from FormBase then override them in both Form1 and Form2. Thats how they will have separate implementations.

    Make FormBase abstract and WindowState property abstract too (to force every deriving form to implement it).


    .NET Maniac -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    Monday, June 11, 2012 5:10 AM
  • Hi Parateek

    Thanks for your reply. I think you understood the issue very well I tried your suggestion. I did set the Windowstate to an abstarct property in the Baseform as follow

    protected abstractFormWindowStateWindowState { get; set; }

    Then override the property in the inherited forms as follow.

        protected override FormWindowState WindowState
        {
            get
            {
                return _WindowState;
            }
            set
            {
                _WindowState = value;
            }
        }

    Then i set the window state for each one of the forms in the calling method separately butstill this didn't solve the issue. any suggestion,

    Thanks in advance



    • Edited by msdnNas Tuesday, June 12, 2012 1:11 AM
    Monday, June 11, 2012 5:57 PM
  • Hi msdnNas,

    Welcome to the MSDN forum.

    Can you provide your complete code for us please? I can't reproduce the issue as your said. Thanks.

    Have a nice day.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Bob Shen Wednesday, June 13, 2012 6:25 AM
    Wednesday, June 13, 2012 6:25 AM
  • Hi Bob,

    Here is part of the code

    ===The code for the main FormBase that other forms are inherited from with the method inside it called ActivateForm to open the children forms
    namespace MaxxLIMS.Core.UI.Win
    {
     public class FormBase : XtraForm, IView
     {
      #region View Events

      /// <summary>
      /// Event handler for Closed view
      /// </summary>
      public event ClosedViewEventHandler OnClosedView;

      /// <summary>
      /// Fires when UIMetadata is set
      /// </summary>
      public event EventHandler OnSetUIMetadata;

      #endregion

      
      private Dictionary<string, string> dataSourcePropertyInfo;
      protected string ActionStatus;

    /// <summary>
      /// Adds or Activetes form to/from Modules
      /// </summary>
      /// <param name="form">Form to activate</param>
      /// <param name="formName">Name of the form to activate</param>
      /// <param name="showForm">Indicates if Show method should be called</param>
      protected void ActivateForm(FormBase form, string formName, bool showForm = true)
      {
       if (!Modules.ContainsKey(formName) && form != null)
       {
        form.OnSetUIMetadata += Form_OnSetUIMetadata;
        form.OnClosedView += Form_OnClosedView;
        form.MdiParent = MdiParent;
        form.ModuleId = formName;
        form.LocationId = LocationId;
        form.ParentFormBase = this;
        Modules.Add(formName, form);
        if (showForm)
        {
         try
         {
          Cursor.Current = UIWinUtil.WaitCursor;
          form.Show();
         }
         catch (Exception ex)
         {
          throw ex;
         }
         finally
         {
          Cursor.Current = Cursors.Default;
         }
        }
       }
       else
        form = (FormBase)Modules[formName];

       if (form != null && showForm)
       {
        form.WindowState = FormWindowState.Normal;
        form.Focus();
       }
      }


    }

      #endregion

     }

    ===Here is the code for the first Child form  called BrowseFormBase which inherited from FormBase and has the methods to open another child form Called EditFormBase===

    namespace MaxxLIMS.Core.UI.Win
    {
     public partial class BrowseFormBase : FormBase
     {
      #region Fields

      private MxUserControlBase editControl;
      private QuickSearchBase quickSearch;
      private bool _IsQuickSearchVisible = true;
      private bool _ApplyTrimOnSearch;
      protected bool _AutoSearchOnPropertyChanged;

      #endregion

      #region Constructor

      public BrowseFormBase()
      {
       InitializeComponent();
       if (!DesignMode)
       {
        barManager.ToolTipController = defaultToolTipControllerBase.DefaultController;
        barManager.ItemClick += OnBarManager_ItemClick;
        CanSetEditControl = true;
        SetQuickSearch();
       }
      }

      public BrowseFormBase(Type editFormType) : this()
      {
       EditFormType = editFormType;
      }

      public BrowseFormBase(MxUserControlBase editControl) : this()
      {
       EditControl = editControl;
      }


      protected  virtual void DisplayEditForm(object sender)
      {
       DisplayEditForm(sender, string.Empty);
      }

      protected void DisplayEditForm(object sender, string name)
      {
       try
       {
        Cursor.Current = UIWinUtil.WaitCursor;
        var gv = (GridView)sender;
        int[] selectRows = gv.Columns.View.GetSelectedRows();
        bool isEditFormOpen = IsEditFormActive;
        if (selectRows != null && (selectRows.Length == 0 || (selectRows.Length > 0 && selectRows[0] < 0))) // selected a group, do nothing.
        {
         if (isEditFormOpen)
          EditForm.Close();
         else if (EditControl != null)
          EditControl.ResetItem();
         return;
        }

        if (selectRows == null || selectRows[0] > ((IList)DataSource).Count - 1)
        {
         gv.FocusedRowHandle = 0;
         return;
        }

        if (UIMetadata.BrowseMetadata.DataKeyNames.Count > 0)
        {
         ShowEditForm(GetDataKeyValuesAsCSV(selectRows), name);
        }
        else
         MessageBox.Show("No DataKeyNames metadata has been specified");
        if (!isEditFormOpen && EditForm != null)
        {
         EditForm.WindowState = FormWindowState.Normal;
         EditForm.Show();
        }
       }
       catch (Exception ex)
       {
        if (CoreUtility.HandleException(ex, ENExceptionPolicy.UI)) throw;
       }
       finally
       {
        Cursor.Current = Cursors.Default;
       }

      }

      /// <summary>
      /// Contains the logic that creates or opens the entry form
      /// The EditFormType property must be set when the browse form is created
      /// </summary>
      /// <param name="id">entity id</param>
      protected virtual void ShowEditForm(string id)
      {
       ShowEditForm(id, string.Empty);
      }

      protected virtual void ShowEditForm(string id, string name)
      {
       if (EditFormType != null)
       {
        string moduleId = EditFormType.FullName;
        if (!Modules.ContainsKey(moduleId))
        {
         EditFormBase editForm = string.IsNullOrEmpty(name) ?
          (EditFormBase)Activator.CreateInstance(EditFormType, id) :
          (EditFormBase)Activator.CreateInstance(EditFormType, id, name);
         editForm.RefreshBrowseList += RefreshBrowseList;
         ActivateForm(editForm, moduleId, false);
         editForm.SetDataNavigator(EditdataNavigator.DataSource, EditdataNavigator.DataSourceController);
        }
        else
        {
         ((EditFormBase)Modules[moduleId]).Focus();
         ((EditFormBase)Modules[moduleId]).ReloadView(id);
        }
       }
       else if (EditControl != null)
       {
        SetEditControl(id);
       }
      }

    }
    }

    ==Here is the code for the second child form called EditFormBase again it is inheriting from FormBase and openned from the first child form called BrowseFormBase above====

    namespace MaxxLIMS.Core.UI.Win
    {
     public partial class EditFormBase : FormBase, IEditView
      {

        # region Custom event

        public event EditFormEntityCreatedEventHandler RefreshBrowseList;
      
        #endregion

        #region Constructor

        public EditFormBase()
        {
          InitializeComponent();
       if (!DesignMode)
       {
        barManager.ToolTipController = defaultToolTipControllerBase.DefaultController;
        barManager.ItemClick += OnBarManager_ItemClick;
       }
      }

        public EditFormBase(string id)
          : this()
        {
          EntityId = id;
        }

        public virtual void ApplyChanges() { }

      public virtual void OnCancelProcess() { }

      public virtual bool CanDeleteItem()
      {
       return UIWinUtil.ConfirmDeleteData();
      }

      public virtual bool CanSaveChanges()
      {
       return UIWinUtil.ConfirmSaveData();
      }

      protected virtual void Display()
        {
       ActionParameters = null;
          if (Controller == null)
          {
        var settings = new ControllerSettings()
        {
         View = this,
         Id = EntityId,
         ApplicationCode = ApplicationCode,
         FormCode = ViewId,
         DataKeyName = DataKeyName,
         EntityName = EntityName
        };
        if (ViewControllerFactory == null)
         Controller = ControllerFactoryBase.GetController(settings);
        else
         Controller = ViewControllerFactory.GetControllerInstance(settings);
       }
          else
          {
            Controller.Settings.Id = EntityId;
          }
          Controller.Display();
        }

      protected override void OnItemClick(string action)
      {
       try
       {
        var currentAction = ActionBase.None;
        currentAction = (ActionBase)Enum.Parse(typeof(ActionBase), action);
        if (!(currentAction == ActionBase.Save || currentAction == ActionBase.Cancel || AllowViewNavigation()))
         return;
        if (currentAction == ActionBase.Close)
         Close();
        else
         UIWinUtil.ProcessEditViewAction(this, action);
       }
       catch (Exception ex)
       {
        if (CoreUtility.HandleException(ex, ENExceptionPolicy.UI)) throw;
       }
       finally
       {
        Cursor = Cursors.Default;
       }
      }

      #endregion

     }
    }

    thanks in advance



    • Edited by msdnNas Wednesday, June 13, 2012 6:49 PM
    Wednesday, June 13, 2012 1:51 PM
  • Hi msdnNas,

    I can't reproduce this issue since the Form is inherit from some third party dll. 

    I can't find any code that set the WindowsState to minizied. I believe this issue is called by the third party dll, please contact them immediately.

    If this is not a third party class, could you please upload the code/demo to the SkyDrive?

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 15, 2012 8:45 AM
  • Hi Bob,

    I can't upload the code to skydrive as this is a big project and all the cod is connected to each other. I want to mention the parent form for all children forms is an MDI Form could this be what is causing this behaviour?


    Nasiem

    Friday, June 15, 2012 4:42 PM
  • Hi Nasiem,

    I'm sorry that I can't detect the issue without the complete code. It seems that you are using DevExpress controls. I suggest you create a new thread in the DevExpress Forum.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 2:38 AM