I'm trying to override the color and rectangle size of the selected main menu item. However I can't tell if the mouse is over that element.
In the BeforeDrawBackColor phase of the Drawfilter on the UltraToolbarsManager:
if (drawParams.Element is PopupMenuItemUIElement){ PopupMenuItemUIElement popupMenuItemUIElement = (PopupMenuItemUIElement)drawParams.Element; if(true) // I'd like to replace this with a check if the mouse is over this menu item { Rectangle originalRect = popupMenuItemUIElement.DrawingRectInsideBorders; SolidBrush solidBrush = drawParams.CreateSolidBrush(DefaultHoverMenuBackgroundColor); Int32 verticalCenteringShift = (originalRect.Height - 20) / 2; Rectangle drawingRect = new Rectangle(originalRect.X+24, originalRect.Y + verticalCenteringShift, originalRect.Width-24, 20); drawParams.Graphics.FillRectangle(solidBrush, drawingRect); allPaintingHandled = true; }}
Thanks.
Hello Abdul,
To set the background color of main menu item the mouse is over you need to get the mouse point and to check if menu item element contains this point. To get the mouse point in screen coordinates you can use such statement:
Point screenPoint = Control.MousePosition;
You need then to transfer this in client coordinates like this:
Point clientPoint = drawParams.Element.Control.PointToClient(screenPoint);
Then you need to check if the clientPoint is in the main menu item element.
Please note it is better to use drawParams.DrawBackColor method instead of drawing a new rectangle. In this way you are follow the drawing your controls.
Please check attached a sample solution and let me know if this is what you are looking for or if I am missing something.
I am just checking about the progress of this issue. Let me know if you need my further assistance on it.
Thank you for using Infragistics Components.
Sincerely,
Milko
Developer Support Engineer
Infragistics
www.infragistics.com/support
So it seems I didn't ask the correct question for the problem I had. I was really trying to track the active menu item to paint the selected color. Because if I hover over an item it all works with your suggested logic, but if I press key up, then it moves selection to the menu item above and I can't detect that its "active". I stepped through the code and found the DrawAsActive property is set to true in the cases I care about. I played around with some Reflection in the draw filter, which I would like to avoid doing to prove that its the property I care about and it worked.
However is there a better way to check the DrawAsActive flag without the two Reflection calls as in the following:
if(drawingElement is PopupMenuItemUIElement) { object context = drawingElement.GetContext(); PropertyInfo propertyInfo = context.GetType().GetProperty("Tool", BindingFlags.Instance | BindingFlags.NonPublic); ToolBase tool = (ToolBase)propertyInfo.GetValue(context, null); propertyInfo = tool.GetType().GetProperty("DrawAsActive", BindingFlags.Instance | BindingFlags.NonPublic); Boolean drawAsActive = (Boolean)propertyInfo.GetValue(tool, null); if(drawAsActive) {
Thank you for your feedback.
Yes, you can achieve this behavior without using reflection. What you need is to get the ToolBase of the PopupMenuItemUIElement context. if the ToolBase IsActiveTool property is true you can redraw the background using the same logic.
Attached I am sending you my revised sample. Please check my sample and let me know if you need any further assistance.
Thank you for using Infragistics controls.