Combine controls into one image to load into RadCarousel

4 posts, 0 answers
  1. Rob Hedgpeth
    Rob Hedgpeth avatar
    7 posts
    Member since:
    May 2011

    Posted 28 Jun 2011 Link to this post

    This question may belong in a different WinForms controls forum. If so, I apologize.

    Ultimately, I am wanting to show a carousel full of RadGridViews, but for performance's sake I am converting the RadGridView's into RadImageItems to be loaded into the carousel.

    I'd like to be able to put a label above the RadGridView as a title for the grid. So far I've tried adding a RadLabel and RadGridView to a RadItemsContainer, and then using the "GetAsBitmap" function to no avail.  

    RadImageItem image1 = new RadImageItem();
    image1.Image = rl.RootElement.GetAsBitmap(Brushes.White, 0, new SizeF(1, 1));
    rl.RootElement.GetAsBitmap(Brushes.White, 0, new SizeF(1, 1));
     
    RadImageItem image2 = new RadImageItem();
    image2.Image = grid.RootElement.GetAsBitmap(Brushes.White, 0, new SizeF(1, 1));
     
    RadItemsContainer ric = new RadItemsContainer();
    ric.Items.Add(image1);
    ric.Items.Add(image2);
     
    RadImageItem image3 = new RadImageItem();
    image3.Image = ric.GetAsBitmap(Brushes.White, 0, new SizeF(1, 1));
    image3.ImageKey = imageKey;

    (rl = previously declared RadLabel, grid = previously declared RadGridView)

    Thanks,

    Rob

  2. Peter
    Admin
    Peter avatar
    1140 posts
    Member since:
    Sep 2012

    Posted 01 Jul 2011 Link to this post

    Hello Rob,

    Thank you for the question.

    We have never tested such a scenario before, but I would like to suggest that you to put a RadGridView and RadLabel into a Panel and call Panel.GetAsBitmap method.

    Another possible solution is to try to combine two bitmaps - paint objects on different layers - here is an interesting article on how to do this.

    I hope this helps.

    Greetings,
    Peter
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.

  3. Rob Hedgpeth
    Rob Hedgpeth avatar
    7 posts
    Member since:
    May 2011

    Posted 01 Jul 2011 Link to this post

    Hey Peter,

    Thanks for your response.

    In case anyone ever has this same issue I was able to solve my problem by creating a bitmap of both the RadGridView and RadLabel, adding the images to a new Bitmap object, and then setting the RadImageItem's Image property to the new Bitmap.

    //Previously instantiated grid
    grid.BeginInit();
    grid.BindingContext = new BindingContext();
    grid.EndInit();
    grid.LoadElementTree();
     
    RadLabel descriptionLabel = new RadLabel();
    descriptionLabel.Text = "Success!";
    descriptionLabel.LoadElementTree();
        
    Bitmap gridBitmap = grid.RootElement.GetAsBitmap(Brushes.White, 0, new SizeF(1, 1));
    Bitmap labelBitmap = descriptionLabel.RootElement.GetAsBitmap(Brushes.White, 0, new SizeF(1, 1));
     
    Bitmap bmp = new Bitmap(x, y, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     
    using (Graphics grfx = Graphics.FromImage(bmp))
    {
       grfx.DrawImage(labelBitmap, 0, 0);
       grfx.DrawImage(gridBitmap, 0, 15);
    }
           
    RadImageItem image = new RadImageItem();
    image.Image = bmp;

    Thanks again,

    Rob

  4. Peter
    Admin
    Peter avatar
    1140 posts
    Member since:
    Sep 2012

    Posted 06 Jul 2011 Link to this post

    Hello Rob,

    Thank you for the sharing this solution with the community.

    Regards,
    Peter
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top