开发者

Find the center of a .NET User Control

I'd like to display an image in the center of my user control, but I'm drawing a blank on actually "finding" the center of the control!

I feel like this should be something very simple but I just can't get my head around it.

Ideally I'd like to end up with X & Y c开发者_如何学运维oordinates which can be added to an instance of Point in order to display at that point.


You can just use ctrl.Width / 2, ctrl.Height / 2.
You may want to add ctrl.Left and ctrl.Top.


If the image should be placed at the center, use this code: (Pseudo, untested)

image.Location = new Point((control.Width / 2) - (image.Width /2),(control.Height / 2) - (image.Height / 2));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜