Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Windows窗体控件上使用RectVisible_C#_C++_Winforms_Gdi - Fatal编程技术网

C# 在Windows窗体控件上使用RectVisible

C# 在Windows窗体控件上使用RectVisible,c#,c++,winforms,gdi,C#,C++,Winforms,Gdi,我试图弄清楚windows窗体控件是否对用户可见,或者是否被另一个控件或窗体(选项卡式视图)挡住了视线。我尝试过GetUpdateStifle,但它只有在最小化窗口的情况下才有效。我找到了该函数,但不确定如何从Windows窗体用户控件使用它 提前感谢我不知道你所说的“只有在最小化窗口的情况下才有效”是什么意思。使用GetUpdate的解决方案可以: [StructLayout(LayoutKind.Sequential)] internal struct RECT { public i

我试图弄清楚windows窗体控件是否对用户可见,或者是否被另一个控件或窗体(选项卡式视图)挡住了视线。我尝试过GetUpdateStifle,但它只有在最小化窗口的情况下才有效。我找到了该函数,但不确定如何从Windows窗体用户控件使用它


提前感谢

我不知道你所说的“只有在最小化窗口的情况下才有效”是什么意思。使用GetUpdate的解决方案可以:

[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);
}

我有两个用户控件,它们位于选项卡控件的不同选项卡页上。当我使用您的代码测试它们时,它们都说是可见的,即使一次只有一个活动选项卡time@unclepaul84我不能重复你的失败。您正在调用的是…可见两次-每个用户控制变量一次?你什么时候调用它?我使用control.Invoke每10秒从计时器线程调用一次