How to align PictureBox content to the right

6 posts, 0 answers
  1. Pavel
    Pavel avatar
    5 posts
    Member since:
    Jun 2012

    Posted 26 Jun 2012 Link to this post

    Hi All,

    I have report with a picturebox:

    Size = 2in, 0.76in
    Anchor = Right, Top
    Sizing = ScaleProportional

    I would like to have the content of the picture box aligned to the right side. Is there any way how to do that? 

    In more detail:
    The value of the image is set in the code based on the current customer logo. Each customer has different proportion of their logos. The size of the PictureBox is the maximum size the logo could occupy on the report. I want to have the logo as big as possible (but not more then the maximum size) and be aligned to the right side of the report.

    Thank you!

    Pavel
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 26 Jun 2012 Link to this post

    Hello Pavel,

    The positioning (and clipping) of an image inside the PictureBox item is controlled via the Sizing property. You can find explanation of the possible values it accepts at the bottom of the PictureBox help article.

    Kind regards,
    Steve
    the Telerik team

    FREE WEBINAR ON THE NEW REPORT DESIGNER! Join us on Friday, June 29 at 10:00 AM PST for a comprehensive demo of the official version of the standalone Report Designer and find out how easy it is to empower your users with creating, editing and sharing ad-hoc reports. You may even win a free Telerik Ultimate Collection license! Register today >>

  3. DevCraft banner
  4. Pavel
    Pavel avatar
    5 posts
    Member since:
    Jun 2012

    Posted 26 Jun 2012 Link to this post

    Hi Steve,

    yes I know and I am using ScaleProportional to fit the image correctly to the picturebox. The problem is how to align the content that I get with this Sizing property to the right. I don't have control over that image and I need to have it placed in the right corner of the report.

    I enclosed an image that should describe better what I want to accomplish. 

    Regards,

    Pavel
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 Jun 2012 Link to this post

    Hi Pavel,

    My previous reply and specifically pointing you to the Sizing property was a way to say that these are the only supported sizing modes and there is no way to align an image to the right of the PictureBox container. Looking at your screenshot, decreasing its width while keeping it positioned at the end of the section would be the best option.

    Greetings,
    Steve
    the Telerik team

    FREE WEBINAR ON THE NEW REPORT DESIGNER! Join us on Friday, June 29 at 10:00 AM PST for a comprehensive demo of the official version of the standalone Report Designer and find out how easy it is to empower your users with creating, editing and sharing ad-hoc reports. You may even win a free Telerik Ultimate Collection license! Register today >>

  6. Squall
    Squall avatar
    174 posts
    Member since:
    Feb 2011

    Posted 03 Sep 2013 Link to this post

    Hi, I had similar issue and in my case the solution was to manually scale the image and then use it in the PictureBox. For this I have made an user function. In your case you may have to  change the draw image rectangle:
    g.DrawImage(image,
    new Rectangle(0,0,(int)srcWidth, (int)srcHeight));


    static float dotsPerInch;
    static float DotsPerInch
    {
        get
        {
            if (0 == dotsPerInch)
            {
                using (Bitmap bitmap = new Bitmap(1, 1))
                using (Graphics gr = Graphics.FromImage(bitmap))
                {
                    dotsPerInch = gr.DpiX;
                }
            }
            return dotsPerInch;
        }
    }
      
    public static object GetImage(byte[] value, SizeU size)
    {
        var stream = new MemoryStream(value);
        var image = Image.FromStream(stream);
      
        float destWidth = size.Width.Value * DotsPerInch; ;
        float destHeight = size.Height.Value * DotsPerInch;
      
        float srcWidth = image.Width;
        float srcHeight = image.Height;
      
        float dX = destWidth / srcWidth;
        float dY = destHeight / srcHeight;
        float ratio = Math.Min(dX, dY);
      
        srcWidth = srcWidth * ratio;
        srcHeight = srcHeight * ratio;
      
        var bigger = new Bitmap((int)(destWidth),
                                (int)(destHeight));
        using (var g = Graphics.FromImage(bigger))
        {
            g.DrawImage(image,new Rectangle(0,0,(int)srcWidth, (int)srcHeight));
            return bigger;
        }
    }
  7. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 15 Apr 2014 in reply to Squall Link to this post

    That was exactly what I needed and it worked perfectly.  Thank you for the productive post.
Back to Top
DevCraft banner