/// <summary> /// Nastaví Layout pro Buttons - nastavuje Visible, Height, velikost a pozici buttonů. /// Pracuje s volnými panely pro obsah a pro buttony. /// Nastaví i souřadnice pro panel <see cref="_ControlPanel"/>. /// </summary> private void DoLayoutButtons() { // Patřičné dokování: if (_ControlPanel.Dock != DockStyle.None) { _ControlPanel.Dock = DockStyle.None; } // Prostor pro ControlPanel a pro buttony: Padding margins = DxComponent.ZoomToGui(this.DesignMargins, this.CurrentDpi); Rectangle innerBounds = this.GetInnerBounds(margins); if (_StatusBar.VisibleInternal && _StatusBar.Height > 0) { innerBounds.Height = innerBounds.Height - _StatusBar.Height; } // Pole buttonů: var buttons = GetLayoutButtons(); // Rozmístit buttony a umístit Content: Rectangle contentBounds = DxComponent.CalculateControlItemsLayout(innerBounds, buttons, this.ButtonsPosition, margins); if (_ControlPanel.Bounds != contentBounds) { _ControlPanel.Bounds = contentBounds; } }
/// <summary> /// Vrátí pole obsahující buttony připravené pro layout /// </summary> /// <returns></returns> private ControlItemLayoutInfo[] GetLayoutButtons() { List <ControlItemLayoutInfo> buttons = new List <ControlItemLayoutInfo>(); // Vytvořím si pracovní pole buttonů, určíme max Width: int widthOneMax = 0; var panelSize = this.ClientSize; foreach (var button in _ButtonControls) { var preferresSize = button.GetPreferredSize(panelSize); if (widthOneMax < preferresSize.Width) { widthOneMax = preferresSize.Width; } buttons.Add(new ControlItemLayoutInfo() { Control = button }); } // Do pracovního pole vložím velikost buttonů = všechny stejně: int innerWidth = widthOneMax.Align(60, 300); int buttonHeight = DxComponent.ZoomToGui(this.ButtonsDesignHeight, this.CurrentDpi); int buttonWidth = innerWidth + (3 * buttonHeight / 2); Size buttonSize = new Size(buttonWidth, buttonHeight); buttons.ForEachExec(l => l.Size = buttonSize); return(buttons.ToArray()); }
/// <summary> /// Rozmístí svoje prvky a upraví svoji výšku /// </summary> protected void DoLayout() { if (_InDoLayoutProcess) { return; } try { _InDoLayoutProcess = true; // tlačítko '_OperatorButton' může být neviditelné! bool operatorButtonVisible = _OperatorButton.VisibleInternal; // Výška textu, výška vnitřní, vnější (reagujeme i na Zoom a Skin): int margins = Margins; int margins2 = 2 * margins; int minButtonHeight = DxComponent.ZoomToGui(24); int minHeight = minButtonHeight + margins2; var clientSize = this.ClientSize; int currentHeight = this.Size.Height; int border = currentHeight - clientSize.Height; int textHeight = _FilterText.Height; int innerHeight = (textHeight < minHeight ? minHeight : textHeight); int outerHeight = innerHeight + border; if (currentHeight != outerHeight) { this.Height = outerHeight; // Tady se vyvolá událost OnClientSizeChanged() a z ní rekurzivně zdejší metoda, ale ignoruje se protože (_InDoLayoutProcess = true;) } // Souřadnice buttonů a textu: int buttonCount = (operatorButtonVisible ? 2 : 1); int buttonSize = innerHeight - margins2; int spaceX = 1; int y = margins; int x = margins; int textWidth = clientSize.Width - margins2 - (buttonCount * (buttonSize + spaceX)); int textY = (innerHeight - textHeight) / 2; if (operatorButtonVisible) { _OperatorButton.Bounds = new Rectangle(x, y, buttonSize, buttonSize); x += (buttonSize + spaceX); } _FilterText.Bounds = new Rectangle(x, textY, textWidth, textHeight); x += (textWidth + spaceX); _ClearButton.Bounds = new Rectangle(x, y, buttonSize, buttonSize); x += (buttonSize + spaceX); OperatorButtonRefresh(); ClearButtonRefresh(); } finally { _InDoLayoutProcess = false; } }