SetBounds和SetBoundsCore有什么区别 [英] What is the difference between SetBounds and SetBoundsCore
问题描述
在WinForms中,可以使用 SetBounds
设置控件的边界,或者,如果创建了用户控件,则可以覆盖 SetBoundsCore
.我想知道,他们俩都一样吗?还是有区别?
In WinForms you can set the bounds of a control using SetBounds
, or if you have created a user control, you can override SetBoundsCore
. I was wondering, does they both do the same or are there any differences?
推荐答案
首先 SetBoundsCore
.
First of all SetBounds
is not virtual, so if you need to run some extra code when the bounds is set, your only options is to override SetBoundsCore
.
SetBounds
进行一些参数验证,并包含基于 BoundsSpecified
参数以正确大小调用 SetBoundsCore
的逻辑.它还确保除非大小实际更改,否则不要调用 SetBoundsCore
.
SetBounds
does some parameter validation, and contains the logic with regards to calling into SetBoundsCore
with the correct size based on the BoundsSpecified
parameter. It also makes sure not to call SetBoundsCore
unless the size actually changes.
换句话说, SetBoundsCore
是实现的核心,而 SetBounds
是包含验证和一些其他内部逻辑的公共入口点.
In other words, SetBoundsCore
is the meat of the implementation, while SetBounds
is the public entry point which contain validation and some other housekeeping logic.
这篇关于SetBounds和SetBoundsCore有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!