Hi,
we have requirement to display an Excel like comment corner marker on the ultragrid cells. I know there isn't a built in way and I need to use a draw filter or a creation filter but I am not sure how exactly to get the bounds on the UIElements rectangle and what I need to draw/create in order to show the Excel like comment marker.
I have used the following code that I got from one of the forums:
Private Function IUIElementDrawFilter_DrawElement(drawPhase As DrawPhase, ByRef drawParams As UIElementDrawParams) As Boolean Implements IUIElementDrawFilter.DrawElement
If TypeOf drawParams.Element Is CellUIElement Then
Dim cell = TryCast(drawParams.Element.GetContext(GetType(UltraGridCell), True), UltraGridCell)
If cell IsNot Nothing AndAlso cell.Column.Index <> 0 AndAlso cell.Tag IsNot Nothing Then
Using blueBrush As New SolidBrush(If(cell.Column.Index Mod 2 = 0, Color.Blue, Color.Red))
Dim rect = drawParams.Element.RectInsideBorders
' Create points that define polygon.
Dim point1 As New Point(rect.X + rect.Width * 7 / 8, rect.Y)
Dim point2 As New Point(rect.X + rect.Width, rect.Y)
Dim point3 As New Point(rect.X + rect.Width, rect.Y + rect.Height / 4)
Dim curvePoints As Point() = {point1, point2, point3}
' Draw polygon to screen.
drawParams.Graphics.FillPolygon(blueBrush, curvePoints)
'drawParams.DrawFocusRectangle(rect, Color.Red, Color.Red)
'drawParams.DrawBorders(UIElementBorderStyle.Raised, Border3DSide.All, rect)
'drawParams.DrawArrowIndicator(ScrollButton.Left, rect, UIElementButtonState.StateButtonDown)
End Using
End If
Return True
Return False
End Function
I am drawing a polygon but that looks very rough and does not exactly sit on the top right corner. also when I resize the cells this just goes bad. I want the size to be constant.
Thanks in advance
Regards
Nasir Amin
Hello Nasir,
Could you please review the sample attached to this post and see if it meets your requirements.Please feel free to let me know if I misunderstood you or if you have any other questions.
Thank you so much Boris. That did exactly what I wanted. I had to convert the code to vb.net and instead of using the +/- 15 value, I used 10 to make the polygon a bit smaller.
Thanks again.
Hello,
I was thinking to give you the same class in VB.NET and I guess it slipped out of my mind when I was writing my post. I am glad to hear that you were able to adjust the code.
Please do not hesitate to contact me if you need any additional assistance.