[英]Using RectVisible on Windows Forms Control
我試圖找出Windows窗體控件對用戶是可見的還是被另一個控件或窗體(選項卡式視圖)所遮擋。 我已經嘗試過GetUpdateRect技巧,但是只有在窗口最小化的情況下它才有效。 我找到了RectVisible函數,但是不確定如何從Windows窗體用戶控件中使用它。
提前致謝
我不確定“僅在最小化窗口時有效”的意思。 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.