This is a migrated thread and some comments may be shown as answers.

How to align PictureBox content to the right

5 Answers 875 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 26 Jun 2012, 06:28 AM
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

5 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 26 Jun 2012, 11:02 AM
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 >>

0
Pavel
Top achievements
Rank 1
answered on 26 Jun 2012, 11:41 AM
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
0
Steve
Telerik team
answered on 27 Jun 2012, 12:13 PM
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 >>

0
Squall
Top achievements
Rank 1
answered on 03 Sep 2013, 07:18 AM
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;
    }
}
0
Joel
Top achievements
Rank 2
answered on 16 Apr 2014, 12:52 AM
That was exactly what I needed and it worked perfectly.  Thank you for the productive post.
Tags
General Discussions
Asked by
Pavel
Top achievements
Rank 1
Answers by
Steve
Telerik team
Pavel
Top achievements
Rank 1
Squall
Top achievements
Rank 1
Joel
Top achievements
Rank 2
Share this question
or