在C#WinForms中控制位置偏移?

问题描述 投票:-1回答:1

在C#WinForms(或Win32 API)中是否有一种方法可以偏移表单子控件的原点{0,0}坐标,而无需将控件添加为父级而不扩展窗口边框?

这就是我的意思:

Change origin WinForms

Win32 API是否具有类似SetChildOffset()函数的功能?我希望窗口边框保持不变。

c# windows winforms winapi
1个回答
1
投票

没有API可以做到这一点。而是使用这个:

private void SetChildOffset(int offset) {
    //get all immediate children of form
    var children = this.Controls.OfType<Control>();

    foreach( Control child in children ) {

        child.Location = new Point( child.Location.X + offset, child.Location.Y + offset );

    }

}
© www.soinside.com 2019 - 2024. All rights reserved.