简体   繁体   English

在Windows窗体控件上使用RectVisible

[英]Using RectVisible on Windows Forms Control

I'm trying to figure out if a windows forms control is visible to the user or is obstructed from view by another control or form (tabbed view). 我试图找出Windows窗体控件对用户是可见的还是被另一个控件或窗体(选项卡式视图)所遮挡。 I have tried GetUpdateRect trick but it only works if the window is minimized. 我已经尝试过GetUpdateRect技巧,但是只有在窗口最小化的情况下它才有效。 I found the RectVisible function, but am not sure how to use it from Windows Forms User control. 我找到了RectVisible函数,但是不确定如何从Windows窗体用户控件中使用它。

Thanks in Advance 提前致谢

I'm not sure what you mean by "Only works if the window is minimized". 我不确定“仅在最小化窗口时有效”的意思。 The solution with GetUpdateRect works: GetUpdateRect的解决方案有效:

[StructLayout(LayoutKind.Sequential)]
internal struct RECT
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;
    public int Width { get { return this.Right - this.Left; } }
    public int Height { get { return this.Bottom - this.Top; } }
}

[DllImport("user32.dll")]
internal static extern bool GetUpdateRect(IntPtr hWnd, ref Rect rect, bool bErase);

public static bool IsControlVisibleToUser(Control control)
{
    control.Invalidate();
    var bounds = control.Bounds;
    var rect = new Rect {Left=bounds.Left, Right = bounds.Right, Top = bounds.Top, Bottom = bounds.Bottom};
    return GetUpdateRect(control.Handle, ref rect, false);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM