Paint VisualItem

3 posts, 1 answers
  1. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 04 Apr 2012 Link to this post

    Hello!

    I have a custom VisualItem "CustomVisualItem : IconListViewVisualItem" which belongs to a ListView with ViewType=IconsView.
    The VisualItem consits of a StackLayoutPanel with 2 LightVisualElements (one is displaying a image and the other displays text).
    The Datasource for the ListView is "List<CustomClass>".

    Now I want to achieve the following:
    - check if VisualItem is Databound to CustomClass
    - when property "Disabled" of CustomClass is true then draw a red X over the VisualItem (a red line from Top-Left to Bottom-Right and one from Top-Right to Bottom-Left)

    This is my current not working solution:
    internal class CustomVisualItem : IconListViewVisualItem
        {
     
    protected override void PaintElement(Telerik.WinControls.Paint.IGraphics graphics, float angle, SizeF scale)
            {
                base.PaintElement(graphics, angle, scale);
     
                var t = this.Data.DataBoundItem as CustomClass;
                if (t != null)
                {
                    if CustomClass.Disabled)
                    {
                        //To shorten the sample, only draw a rectangle                   
                        graphics.FillRectangle(BoundingRectangle, Color.Silver); // The rectangle is not placed over the VisualItem                
                    }
                }       
            }
    }

    How can I place the red X (or the rectangle) over the VisuaItem?
  2. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 09 Apr 2012 Link to this post

    Hello Froggie,

    Thank you for writing.

    The PaintElement method is used for painting the actual element and you cannot draw over child elements. When you add child elements to an element they are placed over their parent. This way your X or rectangle is drawn, but is then covered by the child elements. What you can do is to add another element with the size of the parent, which will cover the other child elements and make it visible when the Disabled property is true. In this element you can use the PaintElement method to draw the X.

    I hope this will be useful for you. If you have further questions, I would be glad to help.

    Greetings,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Froggie
    Froggie avatar
    29 posts
    Member since:
    Jan 2012

    Posted 13 Apr 2012 Link to this post

    Thank you!
    I still have to make some tweaks, but I think that solved my problem.
    If the problem is not solved, then I will let you know it. :-)
Back to Top