开发者

How can I detect when Control.PreferredSize changes?

开发者 https://www.devze.com 2023-01-10 15:08 出处:网络
I\'m using Control.PreferredSize in order to determine what the ScrollableControl.AutoScrollMinSize should be for a Form. This will need to be set whenever the control\'s PreferredSize property change

I'm using Control.PreferredSize in order to determine what the ScrollableControl.AutoScrollMinSize should be for a Form. This will need to be set whenever the control's PreferredSize property changes, but there doesn't appear to be a Control.Preferre开发者_C百科dSizeChanged event. Is there a way to detect when this property changes (possibly using Control.WndProc)? I would prefer to avoid polling the property if it can be avoided.


You can override OnLayout or OnPaint.

    private Size m_CurrentPreferedSize;
    protected override void OnLayout(LayoutEventArgs e)
    {
        base.OnLayout(e);
        Size newSize = PreferredSize;
        if(m_CurrentPreferedSize != newSize)
        {
           m_CurrentPreferedSize  = newSize;
           //Your code here 
        }
    }

PreferredSize is calculated on every call.

0

精彩评论

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