How can i set an transparent image to an ImageAndTextButtonUIElement so only the image is displayed an not the border and the button background. I tried using the Appearance.ImageBackground and set the ThemedElementAlpha to Transparent. But now no Image is displaed at all. When using ImageAndTextButtonUIElement.Image then the image is shown but with border and button background.
Any suggestions?
Thanks and regards
Thorsten Pontow
Hi Andrew,
Thanks for the quick reply. I will have another look at the code on it and get back to you soon. Since I would be adding the button to the structure every time I draw it, I check it first. If the button UIElement is already there, then nothing is done. I check it though, maybe there is still an error.
Hello Thorsten,
I have been investigating into the DrawFilter you have provided, but to be honest I’m a little unsure of the behavior that I am seeing with it. So far, I have not been able to get it to work on my end due to a few missing dependencies as well as the condition that “drawParams.Element” is a PopupMenuItemDescriptionUIElement.
The part that I am rather unsure of in this case is this line and the lines that follow it:
IEnumerable<ImageAndTextButtonUIElement> buttonChildElements = parent.ChildElements.OfType<ImageAndTextButtonUIElement>().ToList();
This makes it sound like you already have a button of some sort within your PopupMenuTool, but in the lines following it appears that you essentially duplicate it and then re-add it to the parent. I might just be misunderstanding the items or objects that you have within your PopupMenuTool, but it seems to me that if there already is a button within your PopupMenuTool, your requirement may be able to be achieved without the use of a DrawFilter?
Would it be possible for you to please provide some additional information on the actual objects / tools that you are placing within the parent PopupMenuTool in this case?
Please let me know if you have any other questions or concerns on this matter.
Hello Andrew, Sorry for the late reply. I had a few days off. Here is the DrawFilter code:
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; using Infragistics.Win; using Infragistics.Win.Misc; using Infragistics.Win.UltraWinMaskedEdit; using Infragistics.Win.UltraWinToolbars; using Stotax.Framework.Common; using Stotax.Framework.Common.MethodPublishing; using Stotax.Framework.Presentation; using Stotax.Framework.Value; using static Infragistics.Win.DrawPhase; using Appearance = Infragistics.Win.Appearance; namespace Stotax.Projects.Templates.Presentation { internal class ToolTipItem : IToolTipItem { readonly string m_toolTipTitle; readonly string m_toolTipText; public ToolTipItem(string toolTipTitle, string toolTipText) { m_toolTipTitle = toolTipTitle; m_toolTipText = toolTipText; } ToolTipInfo IToolTipItem.GetToolTipInfo(Point mousePosition, UIElement element, UIElement previousToolTipElement, ToolTipInfo toolTipInfoDefault) { toolTipInfoDefault.ToolTipImage = ToolTipImage.Info; toolTipInfoDefault.AutoPopDelay = 2000; toolTipInfoDefault.ToolTipText = m_toolTipText; toolTipInfoDefault.Title = m_toolTipTitle; return toolTipInfoDefault; } } public class ToolbarsManagerDrawFilter : IUIElementDrawFilter { private string m_text; private MaskedEditTool m_editor; private ImageList m_imageList; private UltraToolbarsManager m_toolbarsManager; private SdnPUSelector m_mandantSelector; private const int ArrowAreaWidth = 30; private PopupMenuTool m_quickStartPopupMenuTool; public PopupMenuTool QuickStartPopupMenuTool { get => m_quickStartPopupMenuTool; set => m_quickStartPopupMenuTool = value; } public ToolbarsManagerDrawFilter(string text, MaskedEditTool maskedEditTool, ImageList imageList, SdnPUSelector mandantSelector) { m_text = text; m_editor = maskedEditTool; m_toolbarsManager = maskedEditTool.ToolbarsManager; m_imageList = imageList; m_mandantSelector = mandantSelector; } DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { return BeforeDrawForeground | AfterDrawElement; } bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { if (drawParams.Element is PopupMenuItemDescriptionUIElement descriptionUIElement && descriptionUIElement.Value.GetText(true).StartsWith("Zuletzt bearbeitet am") && drawPhase == AfterDrawElement) { if (descriptionUIElement.Control.Parent is Form parentForm && parentForm.Text.Contains("HomeButton")) return false; UIElement parent = descriptionUIElement.Parent; SdnPMItem mandantItem = GetMandantItem(parent); bool isFavorite = !mandantItem["IsQuickstartFavorite"].IsNullOrEmpty; IEnumerable<ImageAndTextButtonUIElement> buttonChildElements = parent.ChildElements.OfType<ImageAndTextButtonUIElement>().ToList(); if (!buttonChildElements.Any()) { ImageAndTextButtonUIElement imageAndTextButtonUIElement = new ImageAndTextButtonUIElement(descriptionUIElement.Parent) { Rect = new Rectangle(parent.RectInsideBorders.Width - ArrowAreaWidth, parent.RectInsideBorders.Top, 16, 16), Style = UIElementButtonStyle.Borderless }; AddImageAndTooltipp(isFavorite, imageAndTextButtonUIElement); imageAndTextButtonUIElement.Appearance = new Appearance(); imageAndTextButtonUIElement.Appearance.BackColor = Color.White; imageAndTextButtonUIElement.ElementClick += ImageAndTextButtonUIElementElementClick; parent.ChildElements.Add(imageAndTextButtonUIElement); } else if (buttonChildElements.Count() == 1) { ImageAndTextButtonUIElement imageAndTextButtonUIElement = buttonChildElements.First(); AddImageAndTooltipp(isFavorite, imageAndTextButtonUIElement); } return true; } if (drawPhase == BeforeDrawForeground) { UIElement parent = null; if (drawParams.Element is TextUIElement uiElement && uiElement.Parent is MaskedEditUIElement) { parent = uiElement.Parent; } else if (drawParams.Element is MaskedEditUIElement maskedEditUIElementFocused && ! (m_editor is null) && !(m_editor.Value is null) && string.IsNullOrEmpty(m_editor.Value.ToString())) { parent = maskedEditUIElementFocused.Parent; } while (!(parent is null)) { if (parent is PopupMenuItemUIElement) { break; } parent = parent.Parent; } if (!(parent is null)) { Rectangle drawingRect = drawParams.ElementDrawingRect; Point centerPoint = new Point(drawingRect.X + drawingRect.Width / 2, drawingRect.Y + drawingRect.Height / 2); SizeF textSize = drawParams.Graphics.MeasureString(m_text, drawParams.Font); Brush textBrush = new SolidBrush(Color.DarkGray); drawParams.Graphics.DrawString(m_text, drawParams.Font, textBrush, new PointF(drawingRect.X + 2, centerPoint.Y - textSize.Height / 2)); return true; } return false; } return false; } private void AddImageAndTooltipp(bool isFavorite, ImageAndTextButtonUIElement imageAndTextButtonUIElement) { if (!isFavorite) { imageAndTextButtonUIElement.Image = m_imageList.Images["QuickStartAddFavorite_16.png"]; imageAndTextButtonUIElement.ToolTipItem = new ToolTipItem("Anheften", "Diesen Mandanten an die Liste anheften."); } else { imageAndTextButtonUIElement.Image = m_imageList.Images["QuickStartRemoveFavorite_16.png"]; imageAndTextButtonUIElement.ToolTipItem = new ToolTipItem("Lösen", "Diesen Mandanten von der Liste lösen."); } } private void ImageAndTextButtonUIElementElementClick(object sender, UIElementEventArgs e) { if (e.Element is ImageAndTextButtonUIElement buttonUIElement) { PopupMenuTool quickStartPopupMenuTool = QuickStartPopupMenuTool; SdnPMItem mandantItem = GetMandantItem(buttonUIElement.Parent); if (!(mandantItem is null)) { if (mandantItem["IsQuickstartFavorite"].IsNullOrEmpty) { mandantItem["IsQuickstartFavorite"] = true; } else { mandantItem["IsQuickstartFavorite"] = false; } mandantItem["LastUsed"] = DateTime.Now; } if (m_mandantSelector.HasMethod("PostacceptEditors")) m_mandantSelector.CallMethodWithCircumventAccessMode(m_mandantSelector, "PostacceptEditors"); MaintenanceUseCaseView maintenanceUseCaseView = m_toolbarsManager.DockWithinContainer as MaintenanceUseCaseView; if (!(maintenanceUseCaseView is null)) { maintenanceUseCaseView.FreezePainting = true; } quickStartPopupMenuTool.ClosePopup(); quickStartPopupMenuTool.DropDown(); if (!(maintenanceUseCaseView is null)) { maintenanceUseCaseView.FreezePainting = false; } } } private SdnPMItem GetMandantItem(UIElement uiElement) { string mandantID = string.Empty; SdnPMItem mandantItem = null; string itemText = uiElement.ChildElements.OfType<TextUIElement>().FirstOrDefault()?.Text; PopupMenuTool popupMenuToolByItemText = m_toolbarsManager.Tools.OfType<PopupMenuTool>().FirstOrDefault(tool => tool.CaptionResolved.Equals(itemText)); if (!(popupMenuToolByItemText is null)) { string key = popupMenuToolByItemText.Key; string[] keyParts = key.Split('#'); if (keyParts.Length == 2) { mandantID = keyParts[1]; if (SdnGuid.IsGuid(mandantID)) { mandantItem = m_mandantSelector.FindFirst(new SdnGuid(mandantID, SdnValueCollection.IDName)); } } } return mandantItem; } } }
I am still a little bit confused as to what you are drawing on your PopupMenuTool’s child tools in this case? From your descriptions in this thread, it sounds like you are drawing a Button with an image inside, but I am not certain on this.
Would it be possible for you to please provide a sample project on this matter that shows what you are drawing, or perhaps just provide the code you are using for your DrawFilter for your PopupMenuTool?
Hello Andrew, actually i have a DrawFilter for a ToolbarManager and i place an onto a PopupMenuTool in UIElementDrawFilter.DrawElement() because i like to offer an additional user interaction on every menu item. It all works fine but I just can't get it to show only the image (a png with transparent background) without the border and the background color of the button (like an menu item image is displayed).