/// <summary> /// Default constructor /// </summary> public FormsDecorator() { FormsPanel.Bounds = ClientRectangle; FormsPanel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; TitleBar.Height = 24; TitleBar.Cursor = Cursors.SizeAll; TitleBar.Paint += OnPaintTitleBar; TitleBar.MouseDown += OnMouseDownInTitleBar; TitleBar.MouseMove += OnMouseMoveInTitleBar; TitleBar.MouseUp += OnMouseUpFromTitleBar; TopMargin.Height = 4; TopMargin.Cursor = Cursors.SizeNS; TopMargin.MouseDown += OnMouseDownInTopMargin; TopMargin.MouseMove += OnMouseMoveInTopMargin; TopMargin.MouseUp += OnMouseUpFromTopMargin; LeftMargin.Width = 4; LeftMargin.Cursor = Cursors.SizeWE; LeftMargin.MouseDown += OnMouseDownInLeftMargin; LeftMargin.MouseMove += OnMouseMoveInLeftMargin; LeftMargin.MouseUp += OnMouseUpFromLeftMargin; RightMargin.Width = 4; RightMargin.Cursor = Cursors.SizeWE; RightMargin.MouseDown += OnMouseDownInRightMargin; RightMargin.MouseMove += OnMouseMoveInRightMargin; RightMargin.MouseUp += OnMouseUpFromRightMargin; BottomMargin.Height = 4; BottomMargin.Cursor = Cursors.SizeNS; BottomMargin.MouseDown += OnMouseDownInBottomMargin; BottomMargin.MouseMove += OnMouseMoveInBottomMargin; BottomMargin.MouseUp += OnMouseUpFromBottomMargin; TitleBar.BackColor = SystemColors.Control; LeftMargin.BackColor = SystemColors.Control; RightMargin.BackColor = SystemColors.Control; BottomMargin.BackColor = SystemColors.Control; FormsPanel.BackColor = SystemColors.Control; FormsPanel.Visible = false; FormsContainerControlCollection forms = (FormsContainerControlCollection)FormsPanel.Controls; forms.TopControlChanged += OnTopFormChanged; _unhighlightTimer.Tick += OnUnhighlightTimer; _unhighlightTimer.Interval = 200; _unhighlightTimer.Enabled = true; }
/// <summary> /// Gets the margins for the top form /// </summary> /// <param name="topOffset">top offset (title height when border style is none or zero when border style is provided)</param> /// <returns>margins</returns> private Margins GetMargins(out int topOffset) { FormsContainerControlCollection forms = (FormsContainerControlCollection)FormsPanel.Controls; Margins margins = FormWrapper.GetMargins(forms.TopControl); topOffset = 0; Form topForm = forms.TopControl as Form; if (topForm != null) { if (topForm.FormBorderStyle == FormBorderStyle.None) { margins.Top = DefaultTopMargin + DefaultTitleHeight; margins.Left = DefaultLeftMargin; margins.Right = DefaultRightMargin; margins.Bottom = DefaultBottomMargin; topOffset = DefaultTitleHeight; } } return(margins); }
/// <summary> /// Select a form /// </summary> /// <param name="form">form to select</param> public void SelectForm(Form form) { FormsContainerControlCollection forms = (FormsContainerControlCollection)FormsPanel.Controls; forms.SetChildIndex(form, 0); }
/// <summary> /// Apply top form margins /// </summary> private void ApplyTopFormMargins() { int topOffset = 0; Margins margins = GetMargins(out topOffset); if (topOffset == 0) { TopMargin.Top = FormsPanel.Top; TopMargin.Left = FormsPanel.Left; TopMargin.Width = FormsPanel.Width; TopMargin.Height = margins.Bottom; TitleBar.Top = TopMargin.Bottom; TitleBar.Left = TopMargin.Left; TitleBar.Width = TopMargin.Width; TitleBar.Height = margins.Top - margins.Bottom; BottomMargin.Top = FormsPanel.Bottom - margins.Bottom; BottomMargin.Left = TopMargin.Left; BottomMargin.Width = TopMargin.Width; BottomMargin.Height = margins.Bottom; LeftMargin.Top = TitleBar.Bottom; LeftMargin.Left = FormsPanel.Left; LeftMargin.Width = margins.Left; LeftMargin.Height = BottomMargin.Top - TitleBar.Bottom; RightMargin.Top = TitleBar.Bottom; RightMargin.Left = FormsPanel.Right - margins.Right; RightMargin.Width = margins.Right; RightMargin.Height = BottomMargin.Top - TitleBar.Bottom; _titleRenderer.ContentTopOffset = 0; } else { TopMargin.Top = FormsPanel.Top - margins.Top; TopMargin.Left = 0; TopMargin.Width = Width; TopMargin.Height = DefaultTopMargin; TitleBar.Top = TopMargin.Bottom; TitleBar.Left = TopMargin.Left; TitleBar.Width = TopMargin.Width; TitleBar.Height = DefaultTitleHeight; BottomMargin.Top = FormsPanel.Bottom; BottomMargin.Left = TopMargin.Left; BottomMargin.Width = TopMargin.Width; BottomMargin.Height = margins.Bottom; LeftMargin.Top = TitleBar.Bottom; LeftMargin.Left = FormsPanel.Left - margins.Left; LeftMargin.Width = margins.Left; LeftMargin.Height = BottomMargin.Top - TitleBar.Bottom; RightMargin.Top = TitleBar.Bottom; RightMargin.Left = FormsPanel.Right; RightMargin.Width = margins.Right; RightMargin.Height = BottomMargin.Top - TitleBar.Bottom; _titleRenderer.ContentTopOffset = DefaultTopTitleOffset; } FormsContainerControlCollection forms = (FormsContainerControlCollection)FormsPanel.Controls; Form selectedForm = forms.TopControl as Form; if (selectedForm != null) { _titleRenderer.Icon = selectedForm.Icon; _titleRenderer.Text = selectedForm.Text; selectedForm.Bounds = FormsPanel.ClientRectangle; } _titleRenderer.TitleBarBounds = TitleBar.ClientRectangle; TitleBar.Invalidate(); }