Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i have been working with this class

Simple Runtime Control Sizing and Dragging Class

I need to be able to constrain proportions i am using this as a image container by placing the image into the background of a panel ontop of another panel wich is the piece of paper to say.

What im having problems with is i need to be able to do is resize, move and rotate and i have sorted out all of thease problems.

now the one thing i need help with is constraining the proportions of the panel when i resize.

when a image is loaded into the background of the panel im getting the propotions fine with this code:

C#
imageWidth = img_old.Width;
imageHeight = img_old.Height;

// Figure out the ratio 397, 561 the maximum size
double ratioX = (double)397 / (double)imageWidth;
double ratioY = (double)561 / (double)imageHeight;
    // use whichever multiplier is smaller
    double ratio = ratioX < ratioY ? ratioX : ratioY;

    // now we can get the new height and width
    int newHeight = Convert.ToInt32(imageHeight * ratio);
    int newWidth = Convert.ToInt32(imageWidth * ratio);
    panelimage.Width = newWidth;
    panelimage.Height = newHeight;



and setting the panel to the correct size with maximum width and height specified

does anyone no how i could go about this

Many Thanks

Robert Duller
Posted
Comments
Sergey Alexandrovich Kryukov 6-Jul-12 15:56pm    
How can you ever "constrain proportion" (it's called "aspect ratio") if you cannot constrain yourself from hard-coding of immediate constants like 397 and 561? This is totally unsupportable. If you need an algorithm (so trivial; all it needs is attention and accurate work), develop an algorithm, not a ad-hoc garbage.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900