Exemplo n.º 1
0
        void OnLocationChanged(object sender, EventArgs e)
        {
            FormBase form     = sender as FormBase;
            IdentKey key      = form.Tag as IdentKey;
            ViewData viewData = GetViewByKey(key);

            viewData.View.DialogSetting = form.DialogSetting;
        }
Exemplo n.º 2
0
 private void UnsubscribeFromForm(FormBase form)
 {
     form.FormClosing     -= new FormClosingEventHandler(OnFormClosing);
     form.FormClosed      -= new FormClosedEventHandler(OnFormClosed);
     form.Activated       -= new EventHandler(OnActivated);
     form.Deactivate      -= new EventHandler(OnDeactivate);
     form.SizeChanged     -= new EventHandler(OnSizeChanged);
     form.LocationChanged -= new EventHandler(OnLocationChanged);
 }
Exemplo n.º 3
0
 private void SubscibeToForm(FormBase form)
 {
     form.FormClosing     += new FormClosingEventHandler(OnFormClosing);
     form.FormClosed      += new FormClosedEventHandler(OnFormClosed);
     form.Activated       += new EventHandler(OnActivated);
     form.Deactivate      += new EventHandler(OnDeactivate);
     form.SizeChanged     += new EventHandler(OnSizeChanged);
     form.LocationChanged += new EventHandler(OnLocationChanged);
 }
Exemplo n.º 4
0
        void OnSizeChanged(object sender, EventArgs e)
        {
            IdentKey key      = GetKeyOfFormBase(sender);
            ViewData viewData = GetViewByKey(key);
            FormBase form     = sender as FormBase;

            if ((viewData.Form.DialogFormOption & DialogFormOption.ShowInOSTaskBar) == 0 && viewData.Form.WindowState == FormWindowState.Minimized && !viewData.IsModal)
            {
                viewData.Form.Hide();
            }
            viewData.View.DialogSetting = form.DialogSetting;
        }
Exemplo n.º 5
0
        IdentKey GetKeyOfFormBase(object sender)
        {
            FormBase form = sender as FormBase;

            if (form == null)
            {
                throw new InvalidOperationException("Sender is not a FormBase.");
            }
            ;
            IdentKey key = form.Tag as IdentKey;

            return(key);
        }
Exemplo n.º 6
0
        int GetFormHeaderHeigth(FormBase form)
        {
            Rectangle screenRectangle = form.RectangleToScreen(form.ClientRectangle);

            return(screenRectangle.Top - form.Top);
        }
Exemplo n.º 7
0
        private IdentKey CreateViewForm(IView view, DialogFormOption options, DialogSetting settings)
        {
            _logger.Debug("CreateViewForm." + view.ToStringExt());
            CheckView(view);

            IdentKey key      = new IdentKey();
            ViewData viewData = new ViewData(view);
            FormBase form     = new FormBase(options);

            form.Owner = _parentForm; //TODO: разобраться на что может повлиять
            form.Tag   = key;
            form.Text  = view.Caption;

            form.Icon = Icon.FromHandle((view.Image as Bitmap).GetHicon());
            Control control = viewData.View.UserControl as Control;
            Size    size    = Size.Add(control.Size, new Size(0, GetFormHeaderHeigth(form)));

            form.Size = size;
            if (settings != null)
            {
                if (settings.Position != null)
                {
                    form.Location = settings.Position;
                }
                if (settings.Size != null)
                {
                    form.Size = settings.Size;
                }
            }
            else
            {
                form.Location = new Point(_parentForm.Location.X + (_parentForm.Width - form.Width) / 2,
                                          _parentForm.Location.Y + (_parentForm.Height - form.Height) / 2);
            }
            view.DialogSetting = form.DialogSetting;

            try
            {
                form.Controls.Add(control);
                control.Dock   = DockStyle.Fill;
                control.Parent = form;

                IDialogResult dialogButtons = view.UserControl as IDialogResult;
                if (dialogButtons != null)
                {
                    IButtonControl okButton = dialogButtons.OkButton as IButtonControl;
                    if (okButton != null)
                    {
                        form.AcceptButton = okButton;
                    }
                    IButtonControl cancelButton = dialogButtons.CancelButton as IButtonControl;
                    if (cancelButton != null)
                    {
                        form.CancelButton = cancelButton;
                    }
                }
                _statusBarButtonController.AddButton(key, viewData.View.Caption, viewData.View.Hint, viewData.View.Image);

                viewData.Form = form;
                _views.Add(key, viewData);
                viewData.View.Ident = key;
                SubscibeToForm(form);
            }
            catch (Exception ex)
            {
                ClearFormResourceSuppress(key, viewData);
                throw ex;
            }

            return(key);
        }