Panel with Shape and Background image

5 posts, 0 answers
  1. Aleksej
    Aleksej avatar
    8 posts
    Member since:
    Aug 2014

    Posted 18 Sep 2014 Link to this post

    I have the rounded panel (pic.1). When I add the picture of a background, curves vanish (pic.2). How to solve a problem?
  2. Aleksej
    Aleksej avatar
    8 posts
    Member since:
    Aug 2014

    Posted 22 Sep 2014 Link to this post

    Up!
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 Sep 2014 Link to this post

    Hi Aleksej,

    Thank you for writing.

    Here is a sample implementation of an element with clipped image, which you can host in RadPanel. I hope that you find it useful.
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        InitializeComponent();
     
        RadPanel panel = new RadPanel();
        panel.Size = new System.Drawing.Size(302, 302);
        panel.Parent = this;
     
        panel.PanelElement.PanelBorder.ForeColor = Color.Red;
        panel.PanelElement.PanelBorder.BorderThickness = new Padding(3);
        panel.PanelElement.Shape = new RoundRectShape(45);
     
        MyElement imp = new MyElement();
        imp.Image = Image.FromFile(@"C:\Users\stefanov\Desktop\a.png");
        imp.ImageLayout = ImageLayout.Tile;
        imp.Shape = panel.PanelElement.Shape;
        panel.PanelElement.Children.Add(imp);
    }
     
    class MyElement : LightVisualElement
    {
        protected override void PaintElement(Telerik.WinControls.Paint.IGraphics graphics, float angle, SizeF scale)
        {
            object state = graphics.SaveState();
     
            Graphics g = (graphics.UnderlayGraphics as Graphics);
     
            Rectangle rect = new Rectangle(0, 0, this.Bounds.Width , this.Bounds.Height );
            g.SetClip(this.Shape.CreatePath(rect), CombineMode.Intersect);
             
            base.PaintElement(graphics, angle, scale);
            
             graphics.RestoreState(state);
        }
    }

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  5. Aleksej
    Aleksej avatar
    8 posts
    Member since:
    Aug 2014

    Posted 23 Sep 2014 Link to this post

    Thanks! And why not to realize it in RadPanel?
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 23 Sep 2014 Link to this post

    Hello,

    We will consider it if we have more request for such functionality.

    Regards,
    Stefan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready