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

Picture box alignment

7 Answers 918 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James Shelton Agar
Top achievements
Rank 2
James Shelton Agar asked on 03 Feb 2011, 05:32 AM
When working with picturebox, which sizing is "ScaleProptional", can we set alignment to be at right? dock doesn't seems to be working

7 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 03 Feb 2011, 05:38 PM
Hi James,

The TextAlign and VerticalAlign properties do not contain any meaning for the PictureBox item they are both responsible for alignment of text.
The Dock property determines how a report item is resized with its parent e.g. setting Dock to Bottom causes the report item to align itself with the bottom edges of its parent and to resize as the parent is resized.

Regards,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
James Shelton Agar
Top achievements
Rank 2
answered on 03 Feb 2011, 11:27 PM
when the image width is random, if the width wider than PictureBox, it will scaled by ratio but if less than PictureBox's width, image will aligned into center, any idea?
0
Steve
Telerik team
answered on 07 Feb 2011, 05:25 PM
Hello James,

This is the behavior by design. Here is the description of the ScaleProportional property from the PictureBox help article:
"The image is sized proportionally (without clipping), so that it's best fitted to the picturebox item. If the height and width ratio of the picturebox item is the same as the image's ratio it will be resized to exactly fit into the picturebox item. Otherwise the closest fitting side (height or width) of the image will be sized to the item and the other side (height or width) of the image sized proportionally (leaving empty space)."

Kind regards,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Morten Louw
Top achievements
Rank 1
answered on 06 May 2011, 09:32 AM
I agree. It would be nice to be able to control the alignment of the open content. The white filling area.
Not the textalign, but a picturealign!

My hack will be to analyze the pictures pixel-dimensions using System.Drawing.Image, and set the picturebox width based on that.
It has to be by code. It would have been nice to do databinding instead - and a more declarative approach in general...

Kind Regards,
Morten
David
Top achievements
Rank 1
commented on 16 Jan 2022, 02:10 PM

Hey Morten, any chance you could post that code? It would be super helpful for me.
0
Chavdar
Telerik team
answered on 11 May 2011, 03:30 PM
Hi Morten Louw,

Here is one more suggestion before you implement your solution with code. Try with PictureBox.Sizing mode set to AutoSize and then dock the PictureBox item to the right. In this case the width of the PictureBox should be set to the greatest possible image width and the detail section's width should be that of the page without margins. If this approach does not help then as a last resort you can specify the size and the location of the PictureBox item using user functions and bindings.

Best wishes,
Chavdar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 27 Jan 2017, 08:17 PM

we are running into the same issue. Any other tools that we have used when using the scaling of "Scale Proportional", the image us usually aligned TOP/LEFT. In the Telerik PictureBox control, it's always CENTERED both Vertically and Horizontally. I know this thread is old, but is there any way to have an option, in the future, to allow us to how to align the image after it is scaled in the control?

 

Thanks

0
Katia
Telerik team
answered on 01 Feb 2017, 02:48 PM
Hi Mark,

This option is not supported at the moment.

Feel free to add a request for it into our feedback portal and describe the exact functionality you expect from a PictureBox item.
This way other community members also interested in this functionality can vote for it which will raise its priority. New features are selected for development based on the interest from the community members.


Regards,
Katia
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
David
Top achievements
Rank 1
commented on 16 Jan 2022, 01:58 PM

I'm really surprised this isn't supported.

Looks like the only workaround to this is what another user commented: My hack will be to analyze the pictures pixel-dimensions using System.Drawing.Image, and set the picturebox width based on that.

David
Top achievements
Rank 1
commented on 16 Jan 2022, 04:33 PM

Hoping this might be helpful to someone, this is the code I came up with that will resize the PicutreBox to the actual width, so you don't get any left/right padding.

var width = pngLogoImage.Width;
var height = pngLogoImage.Height;
var resolution = pngLogoImage.VerticalResolution;
var widthInInches = width / resolution;
var heightInInches = height / resolution;

var picBoxWidth = companyLogoPictureBox.Width.Value;
var picBoxHeight = companyLogoPictureBox.Height.Value;

if (widthInInches > picBoxWidth || heightInInches > picBoxHeight)
{
	double ratioX = (double)picBoxWidth / widthInInches;
	double ratioY = (double)picBoxHeight / heightInInches;
	double ratio = Math.Min(ratioX, ratioY);

	var newWidth = widthInInches * ratio;
	var newHeight = heightInInches * ratio;

	companyLogoPictureBox.Width = Unit.Inch(newWidth);
	companyLogoPictureBox.Height = Unit.Inch(newHeight);
}

 

Neli
Telerik team
commented on 19 Jan 2022, 02:00 PM

Hi David,

Have you tested different values for the Sizing property? For example, the Stretch ImageSizeMode.

Tags
General Discussions
Asked by
James Shelton Agar
Top achievements
Rank 2
Answers by
Steve
Telerik team
James Shelton Agar
Top achievements
Rank 2
Morten Louw
Top achievements
Rank 1
Chavdar
Telerik team
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Katia
Telerik team
Share this question
or