保持控制为中心 [英] Keeping control centered

查看:66
本文介绍了保持控制为中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让控件在窗体中居中而不必每次调整窗体大小时重新计算



Is there a way to keep a control centered inside a form without having
to recalculate everytime the form is resized?

推荐答案

没有人,


是的,有。当控件首次放在窗体上时,执行

计算以使控件居中。完成后,设置Anchor属性

,使其锚定到其容器的所有边。如果您在设计时将

控件放在容器中,那么只需将控件置于中心位置,然后在设计时设置Anchor属性。

希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


No One <无*** @ yahoo.com>在消息中写道

新闻:40 *************** @ yahoo.com ...
No One,

Yes, there is. When the control is first placed on the form, perform
the calcs to center the control. Once you do that, set the Anchor property
so that it anchors to all sides of its container. If you are placing the
control in the container at design time, then just center the control and
set the Anchor property at design time.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"No One" <no***@yahoo.com> wrote in message
news:40***************@yahoo.com...
有没有办法保持一个控件集中在一个窗体内,而不是每次调整窗体大小时重新计算?
Is there a way to keep a control centered inside a form without having
to recalculate everytime the form is resized?



On Tue,2004年6月22日08:18:05 -0400,Nicholas Paldino [.NET / C#MVP]< mv*@spam.guard.caspershouse.com>写道:
On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
没有人,

是的,有。当控件首次放在窗体上时,执行计算以使控件居中。完成后,设置Anchor属性
,使其锚定到其容器的所有边。如果您在设计时将
控件放在容器中,那么只需将控件置于中心位置即可在设计时设置Anchor属性。

希望这会有所帮助。
No One,

Yes, there is. When the control is first placed on the form, perform
the calcs to center the control. Once you do that, set the Anchor property
so that it anchors to all sides of its container. If you are placing the
control in the container at design time, then just center the control and
set the Anchor property at design time.

Hope this helps.




这会产生调整控件大小的副作用。锚定确保到侧面的距离是恒定的,如果您上下左右或左右锚定,它将调整控件的大小。我担心你必须重新计算Form'的SizeChanged活动中的位置。


-

快乐编码!

Morten Wennevik [C#MVP]



This will have the side effect of resizing the control though. Anchoring makes sure the distance to the side is constant, and if you anchor both up and down or left and right it will resize the control. I am afraid you will have to recalculate the position in the Form''s SizeChanged event.

--
Happy coding!
Morten Wennevik [C# MVP]


>>这会产生调整控件大小的副作用。 <<

我怀疑他是否希望控制器的大小保持不变,并且在它增长和缩小的边缘附近有b
,这看起来很奇怪。事实上,

似乎是一个有固定对话边框的候选人。


尼古拉斯建议的另一种选择 - 设置Dock的属性对象

来填充,并调整表格的DockPadding属性来设置边距

大小。


-

John Wood

电子邮件:来自priorganize.com的名字,点,第二名

" Morten Wennevik" <莫************ @ hotmail.com>在消息中写道

news:opr9zzv5hnklbvpo@morten_x.edunord ...
>>This will have the side effect of resizing the control though. <<
I doubt he would want the size of the control to remain constant, and have
the margin around it growing and shrinking, that would look just weird. And,
in fact, would seem like a candidate to have a fixed dialog border.

An alternative to Nicholas'' suggestion - set the Dock property of the object
to Fill, and adjust the DockPadding property of the form to set the margin
size.

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr9zzv5hnklbvpo@morten_x.edunord...
2004年6月22日星期二08:18:05 -0400,Nicholas Paldino [.NET / C# MVP]
< mv*@spam.guard.caspershouse.com>写道:
On Tue, 22 Jun 2004 08:18:05 -0400, Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
没有人,

是的,有。当控件首次放在窗体上时,
执行计算以使控件居中。完成后,设置Anchor
属性,使其锚定到其容器的所有边。如果你在设计时将
控件放在容器中,那么只需将控件
置于中心并在设计时设置Anchor属性。

希望这会有所帮助。

这会产生调整控件大小的副作用。锚定
No One,

Yes, there is. When the control is first placed on the form, perform the calcs to center the control. Once you do that, set the Anchor property so that it anchors to all sides of its container. If you are placing the control in the container at design time, then just center the control and set the Anchor property at design time.

Hope this helps.
This will have the side effect of resizing the control though. Anchoring



确保到边的距离是恒定的,如果你将两者都锚定在向上或向左或向左,它将调整控件的大小。我担心你会不会在表格'SizeChanged事件中重新计算

-
快乐的编码!
Morten Wennevik [C#MVP]


makes sure the distance to the side is constant, and if you anchor both up
and down or left and right it will resize the control. I am afraid you will
have to recalculate the position in the Form''s SizeChanged event.
--
Happy coding!
Morten Wennevik [C# MVP]



这篇关于保持控制为中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆