/// <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> /// Inicializace panelu a jeho komponent /// </summary> protected void Initialize() { _Margins = 1; _OperatorButtonImageDefault = ImageName.DxFilterBoxMenu; _OperatorButtonImageName = null; _ClearButtonImageDefault = ImageName.DxFilterClearFilter; _ClearButtonImage = null; _ClearButtonToolTipTitle = DxComponent.Localize(MsgCode.DxFilterBoxClearTipTitle); _ClearButtonToolTipText = DxComponent.Localize(MsgCode.DxFilterBoxClearTipText); _OperatorButton = DxComponent.CreateDxMiniButton(0, 0, 24, 24, this, OperatorButton_Click, tabStop: false); _FilterText = DxComponent.CreateDxTextEdit(24, 0, 200, this, tabStop: true); _FilterText.KeyDown += FilterText_KeyDown; _FilterText.KeyUp += FilterText_KeyUp; _FilterText.EditValueChanged += _FilterText_EditValueChanged; _ClearButton = DxComponent.CreateDxMiniButton(224, 0, 24, 24, this, ClearButton_Click, tabStop: false); _FilterText.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder; this.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.HotFlat; this.Leave += DxFilterBox_Leave; AcceptOperators(); _CurrentText = ""; FilterValueChangedSources = DxFilterBoxChangeEventSource.Default; LastFilterValue = null; }
/// <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> /// Inicializace vnitřního layoutu - splitpanel /// </summary> private void InitFrames() { int splitterPosition = Data.App.Config.MainSplitterPosition; _MainSplitContainer = DxComponent.CreateDxSplitContainer(this, _SplitterPositionChanged, DockStyle.Fill, Orientation.Vertical, DXE.SplitFixedPanel.Panel1, splitterPosition, DXE.SplitPanelVisibility.Both, true); }
/// <summary> /// Vytvoření controlů /// </summary> private void InitializeControls() { _ControlPanel = DxComponent.CreateDxPanel(this, DockStyle.Fill, borderStyles: DevExpress.XtraEditors.Controls.BorderStyles.NoBorder); _StatusBar = DxComponent.CreateDxStatusBar(this); _ButtonsVisible = null; _ButtonsDesignHeight = DxComponent.DefaultButtonHeight; _ButtonsPosition = ToolbarPosition.BottomSideLeft; _DesignMargins = DxComponent.DefaultInnerMargins; DialogResult = DialogResult.None; CloseOnClickButton = true; }
/// <summary> /// Aktivuje menu položek typů filtru /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OperatorButton_Click(object sender, EventArgs args) { var filterItems = this.FilterOperators; if (filterItems == null || filterItems.Count == 0) { return; } var popup = DxComponent.CreateDXPopupMenu(filterItems, "", showCheckedAsBold: true, itemClick: OperatorItem_Click); Point location = new Point(0, this.Height); popup.ShowPopup(this, location); }
/// <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; } }
private void CreateTreeView() { _SplitContainer = DxComponent.CreateDxSplitContainer(this, null, DockStyle.Fill, Orientation.Vertical, SplitFixedPanel.Panel1, 280, showSplitGlyph: true); _TreeList = new DxTreeViewListSimple() { Dock = DockStyle.Fill }; _TreeList.SelectImageList = _Images16; _TreeList.StateImageList = _Images16; _TreeList.ImageIndexSearcher = GetImageIndex; _TreeList.LazyLoadNodeText = "Copak to tu asi bude?"; _TreeList.LazyLoadNodeImageName = "hourglass_16"; _TreeList.EditorShowMode = TreeListEditorShowMode.Click; _TreeList.Parent = this; _SplitContainer.Panel1.Controls.Add(_TreeList); // Musí být dřív než se začne pracovat s daty!!! DateTime t0 = DateTime.Now; var nodes = _CreateSampleList(ItemCountType.Big); DateTime t1 = DateTime.Now; _TreeList.AddNodes(nodes); DateTime t2 = DateTime.Now; _TreeList.NodeSelected += _TreeList_AnyAction; _TreeList.NodeDoubleClick += _TreeList_AnyAction; _TreeList.NodeExpanded += _TreeList_AnyAction; _TreeList.NodeCollapsed += _TreeList_AnyAction; _TreeList.ActivatedEditor += _TreeList_AnyAction; _TreeList.EditorDoubleClick += _TreeList_AnyAction; _TreeList.NodeEdited += _TreeList_NodeEdited; _TreeList.NodeDelete += _TreeList_NodeDelete; _TreeList.LazyLoadChilds += _TreeList_LazyLoadChilds; int y = 0; _MemoEdit = DxComponent.CreateDxMemoEdit(0, ref y, 100, 100, this._SplitContainer.Panel2, readOnly: true); _MemoEdit.Dock = DockStyle.Fill; _LogId = 0; _Log = ""; string line = "Počet nodů: " + nodes.Count.ToString(); _AddLogLine(line); line = "Tvorba nodů: " + ((TimeSpan)(t1 - t0)).TotalMilliseconds.ToString("##0.000") + " ms"; _AddLogLine(line); line = "Plnění do TreeView: " + ((TimeSpan)(t2 - t1)).TotalMilliseconds.ToString("##0.000") + " ms"; _AddLogLine(line); }
/// <summary> /// Pro daný button refreshuje jeho Image a ToolTip /// </summary> /// <param name="button"></param> /// <param name="imageName"></param> /// <param name="toolTipTitle"></param> /// <param name="toolTipText"></param> /// <param name="imageNameDefault"></param> private void ButtonRefresh(DxSimpleButton button, string imageName, string toolTipTitle, string toolTipText, string imageNameDefault = null) { if (button == null) { return; } if (String.IsNullOrEmpty(imageName)) { imageName = imageNameDefault; } Size imageSize = DxComponent.GetOptimalImageSize(button.Size, 3); DxComponent.ApplyImage(button.ImageOptions, imageName, null, ResourceImageSizeType.Small, imageSize, true); button.SetToolTip(toolTipTitle, toolTipText); }
/// <summary> /// Z dodaného jména souboru určí příponu, podle ní detekuje typ obsahu (dá do out parametru) a detekovanou příponu odřízne (včetně tečky). /// Vrátí true, pokud nějakou příponu detekoval a odřízl (tedy <paramref name="contentType"/> je jiný než None). /// Vrátí false, když je vstup prázdný, nebo bez přípony nebo s neznámou příponou, pak příponu neodřízne. /// <para/> /// Například pro vstup: "C:/Images/Button-24x24.png" detekuje <paramref name="contentType"/> = <see cref="ResourceContentType.Bitmap"/>, /// a v ref parametru <paramref name="name"/> ponechá: "C:/Images/Button-24x24". /// <para/> /// Tato metoda se typicky volá před metodou <see cref="RemoveSizeTypeBySuffix(ref string, out ResourceImageSizeType)"/>, protože tady se řeší a odřízne přípona, a následně se tam řeší suffix jména souboru. /// </summary> /// <param name="name"></param> /// <param name="contentType"></param> private static bool RemoveContentTypeByExtension(ref string name, out ResourceContentType contentType) { contentType = ResourceContentType.None; if (String.IsNullOrEmpty(name)) { return(false); } name = name.TrimEnd(); string extension = System.IO.Path.GetExtension(name).ToLower(); contentType = DxComponent.GetContentTypeFromExtension(extension); if (contentType != ResourceContentType.None) { name = name.Substring(0, name.Length - extension.Length); } return(contentType != ResourceContentType.None); }
private static void CreateDefaultOperatorItem(FilterBoxOperatorItems items, FilterBoxOperatorItems value, string hotKey, string imageName, MsgCode textCode, MsgCode toolTipCode, List <IMenuItem> menuItems) { if (!items.HasFlag(value)) { return; } menuItems.Add(new DataMenuItem() { ItemId = value.ToString(), HotKey = hotKey, ImageName = imageName, Text = DxComponent.Localize(textCode), ToolTipText = DxComponent.Localize(toolTipCode), Checked = false, Tag = value }); }
/// <summary> /// Načte obsah souboru "ServerResources.bin" z určeného adresáře (počet úrovní nahoru nahoru od aktuálního, a daný subdir) /// </summary> /// <param name="resourcePath"></param> /// <param name="upDirs"></param> /// <param name="subDir"></param> /// <param name="resourceList"></param> private static void LoadFromResourcesBinInDirectory(string resourcePath, int upDirs, string subDir, List <IResourceItem> resourceList) { string path = resourcePath; for (int i = 0; i < upDirs && !String.IsNullOrEmpty(path); i++) { path = System.IO.Path.GetDirectoryName(path); } if (String.IsNullOrEmpty(path)) { return; } if (!String.IsNullOrEmpty(subDir)) { path = System.IO.Path.Combine(path, subDir); } string fileName = System.IO.Path.Combine(path, "ServerResources.bin"); System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); if (!fileInfo.Exists) { return; } int fileLengthMB = (int)(fileInfo.Length / 1000000L); if (fileLengthMB > 150) { return; } try { var startTime = DxComponent.LogTimeCurrent; byte[] content = System.IO.File.ReadAllBytes(fileInfo.FullName); LoadFromResourcesBinInArray(content, resourceList); var microsecs = DxComponent.LogGetTimeElapsed(startTime, DxComponent.LogTokenTimeMicrosec); } catch (Exception exc) { DxComponent.ShowMessageError($"Error on loading resources from file {fileInfo.FullName}: {exc.Message}", "Error"); } }
/// <summary> /// Inicializace objektu seznamu grafů, součástí je i načtení seznamu grafů z disku /// </summary> private void InitList() { LoadGraphs(); _GraphListBox = DxComponent.CreateDxListBox(DockStyle.Fill, parent: _MainSplitContainer.Panel1, selectedIndexChanged: _GraphListBox_SelectedIndexChanged, multiColumn: false, selectionMode: SelectionMode.One, itemHeightPadding: 3, reorderByDragEnabled: true); _GraphListBox.DataSource = _Graphs; _GraphListBox.SelectedIndex = 0; // var mcx = DXE.MultiColumnListBoxCreator.CreateMultiColumnListBox(); /* * DXE.TableLayout.ItemTemplateBase template = new DXE.TableLayout.ItemTemplateBase(); // DXE.TableLayout.ItemTemplateBase(); * * template.Name = "TemplateD"; * * template.Rows.Add(new DXE.TableLayout.TableRowDefinition() { AutoHeight = false, Length = new DXE.TableLayout.TableDefinitionLength() { Type = DXE.TableLayout.TableDefinitionLengthType.Pixel, Value = 18 } }); * template.Rows.Add(new DXE.TableLayout.TableRowDefinition() { AutoHeight = true, Length = new DXE.TableLayout.TableDefinitionLength() { Type = DXE.TableLayout.TableDefinitionLengthType.Pixel, Value = 32 } }); * template.Columns.Add(new DXE.TableLayout.TableColumnDefinition() { Length = new DXE.TableLayout.TableDefinitionLength() { Type = DXE.TableLayout.TableDefinitionLengthType.Star, Value = 1000 } }); * template.Columns.Add(new DXE.TableLayout.TableColumnDefinition()); * * DXE.TableLayout.TemplatedItemElement e0 = new DXE.TableLayout.TemplatedItemElement() { RowIndex = 0, ColumnIndex = 0, FieldName = "Title", Height = 18, TextLocation = new Point(8, 2), StretchHorizontal = true }; * e0.StretchHorizontal = true; * e0.StretchVertical = true; * e0.Appearance.Normal.FontSizeDelta = 1; * e0.Appearance.Normal.FontStyleDelta = FontStyle.Bold; * * DXE.TableLayout.TemplatedItemElement e1 = new DXE.TableLayout.TemplatedItemElement() { RowIndex = 1, ColumnIndex = 0, FieldName = "Description", Height = 32, TextLocation = new Point(8,2), StretchHorizontal = true }; * e1.Appearance.Normal.FontStyleDelta = FontStyle.Italic; * * * template.Elements.Add(e0); * template.Elements.Add(e1); * * _GraphListBox.Templates.Add(template); * _GraphListBox.ItemAutoHeight = true; * _GraphListBox.ItemHeight = 50; */ }
/// <summary> /// Vyrenderuje dodaný text jako náhradní ikonu /// </summary> /// <param name="caption"></param> /// <param name="sizeType"></param> /// <param name="imageSize"></param> /// <returns></returns> public static Image CreateCaptionImage(string caption, ResourceImageSizeType?sizeType, Size?imageSize) { var realSize = imageSize ?? DxComponent.GetImageSize((sizeType ?? ResourceImageSizeType.Large), true); bool isDark = DxComponent.IsDarkTheme; Bitmap bitmap = new Bitmap(realSize.Width, realSize.Height); using (var graphics = Graphics.FromImage(bitmap)) { RectangleF bounds = new RectangleF(0, 0, realSize.Width, realSize.Height); graphics.FillRectangle((isDark ? Brushes.MidnightBlue : Brushes.MintCream), bounds); string text = DxComponent.GetCaptionForIcon(caption); if (text.Length > 0) { var font = SystemFonts.MenuFont; var textSize = graphics.MeasureString(text, font); var textBounds = textSize.AlignTo(bounds, ContentAlignment.MiddleCenter); graphics.DrawString(text, font, (isDark ? Brushes.White : Brushes.Black), textBounds.Location); } } return(bitmap); }
/// <summary> /// Do formuláře vytvoří buttony podle obsahu pole <see cref="_IButtons"/>. /// Buttony vytvoří, i když nemají být viditelné (<see cref="_ButtonsVisible"/>, to je úkolem metody <see cref="DoLayout"/>. /// </summary> private void CreateButtons() { RemoveButtons(); var iButtons = _IButtons; if (iButtons is null) { return; } List <DxSimpleButton> buttonControls = new List <DxSimpleButton>(); int x = 5; foreach (var iButton in iButtons) { var buttonControl = DxComponent.CreateDxSimpleButton(x, 0, 100, 20, this, iButton); buttonControl.Click += ButtonControl_Click; x += 105; buttonControls.Add(buttonControl); } _ButtonControls = buttonControls.ToArray(); DoLayout(); }
/// <summary> /// Vytvoří <see cref="SvgImage"/> pro daný text, namísto chybějící ikony. /// Pokud vrátí null, zkusí se provést <see cref="CreateCaptionImage(string, ResourceImageSizeType?, Size?)"/>. /// </summary> /// <param name="caption"></param> /// <param name="sizeType"></param> /// <param name="imageSize"></param> /// <returns></returns> public static SvgImage CreateCaptionVector(string caption, ResourceImageSizeType?sizeType, Size?imageSize) { string text = DxComponent.GetCaptionForIcon(caption).ToUpper(); if (text.Length > 2) { text = text.Substring(0, 2); } bool isWidth = (text == "MM" || text == "OO" || text == "WW" || text == "QQ" || text == "AA"); string fillClass = "White"; string borderClass = "Blue"; string textClass = "Black"; string sizePx = (isWidth ? "16px" : "18px"); string textY = (isWidth ? "20" : "22"); string weight = (isWidth ? "600" : "800"); // bold string svgContent = @"<?xml version='1.0' encoding='UTF-8'?> <svg x='0px' y='0px' viewBox='0 0 32 32' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' id='Layer_1' style='enable-background:new 0 0 32 32'> <style type='text/css'> .White{fill:#FFFFFF;} .Red{fill:#D11C1C;} .Green{fill:#039C23;} .Blue{fill:#1177D7;} .Yellow{fill:#FFB115;} .Black{fill:#727272;} .st0{opacity:0.75;} .st1{opacity:0.5;} </style> <g id='icon" + text + @"' style='font-size: " + sizePx + @"; text-anchor: middle; font-family: serif; font-weight: " + weight + @"'> <path d='M31,0H1C0.5,0,0,0.5,0,1v30c0,0.5,0.5,1,1,1h30c0.5,0,1-0.5,1-1V1C32,0.5,31.5,0,31,0z M30,30H2V2h28V30z' class='" + borderClass + @"' /> <path d='M30,30H2V2h28V30z' class='" + fillClass + @"' /> <text x='16' y='" + textY + @"' class='" + textClass + @"'>" + text + @"</text> </g> </svg>"; svgContent = svgContent.Replace("'", "\""); return(DxSvgImage.Create(caption, DxSvgImagePaletteType.Explicit, svgContent)); /* * * <?xml version='1.0' encoding='UTF-8'?> * <svg x="0px" y="0px" viewBox="0 0 32 32" * version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" * id="Layer_1" * style="enable-background:new 0 0 32 32"> * <style type="text/css"> * .Red{fill:#D11C1C;} * .Green{fill:#039C23;} * .Blue{fill:#1177D7;} * .Yellow{fill:#FFB115;} * .Black{fill:#727272;} * .st0{opacity:0.75;} * .st1{opacity:0.5;} * </style> * <g id="iconAB" style="font-size: 16px; text-anchor: middle; font-family: serif; font-weight: bold"> * <path d="M31,0H1C0.5,0,0,0.5,0,1v30c0,0.5,0.5,1,1,1h30c0.5,0,1-0.5,1-1V1C32,0.5,31.5,0,31,0z M30,30H2V2h28V30z" class="Black" /> * <!-- path d="M0,0L31,0L31,31L0,31L0,0Z" class="Black" / --> * <text x="16" y="20" class="Blue">MM</text> * </g> * </svg> * */ }