Hi,
Can someone please tell me the best way to keep an image horizontally and vertically centered in the window, no matter what dimension the window is resized to (without the image changing size)?
I have been thinking about this for hours, and cannot work out how to achieve this
If I load the image in the canvas.paint event - as soon as the canvas gets stretched due to the user resizing the window, my image will no longer fill up the entire canvas.
Example:
I have a 500 x 500 window, and I need a 200 x 200 image to remain horizontally and vertically centered - even when the window is resized.
Jeff / Eli,
I can’t do that as there will be other controls in the window.
Basically, my canvas will act as a cover (hiding the window content).
Depending on the user’s action - I will then hide the canvas - revealing the window content underneath.
You should be able to keep the canvas 200x200, same size as your image. In the “Resized” and “Resizing” event handlers of your window, add code to set the top and left properties of your canvas.
Thank you all for the help, but I think I will have to forget this idea, as Retina Kit also comes into the equation, therefore I can only define the image name in the canvas.paint event, as far as I can tell.
The only way I can see this being practical, is if it’s possible to draw an image into the absolute centre of a canvas - that way it doesn’t matter if the canvas gets resized.
My head hurts.
Thank you all anyways. (is anyways a word?)
If you want to align the image for all the alignments and not only center the rule is simple:
0.0 - for top or left
0.5 - for center
1.0 - for bottom or right
so, for example if you want to keep your image linked to the bottom - center:
g.drawpicture thepicture,(me.width - thepicture.width)0.5, (me.height - hepicture.height) 1.0 ,thepicture.width ,thepicture.height ,0 ,0 ,thepicture.width ,thepicture.height