【问题标题】:Inconsistent accessibility although class public尽管类公开,但可访问性不一致
【发布时间】:2016-04-15 02:49:18
【问题描述】:

我不断收到“不一致的可访问性”的两个错误,表明“...比方法...更难访问”。

我一直在寻找解决这个问题的方法,每个答案基本上都是“公开课程”。

因此我被卡住了,因为课程已经公开了。

这里是错误发生的地方:

[DllImport("User32.Dll")]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);

/// <summary>
/// Get the inner bounds of client window 
/// </summary>
/// <param name="hWnd"></param>
/// <returns></returns>
public static RECT GetClientRect(IntPtr hWnd)
{
    RECT result;
    GetClientRect(hWnd, out result);
    return result;
}

【问题讨论】:

  • 阅读整个错误信息。它可能在抱怨RECT
  • 你是对的。我把它改成了矩形,现在可以了。

标签: c#


【解决方案1】:

是的,我知道 RECT 应该可以工作。我意识到我做错了什么。

[DllImport("User32.Dll")]
public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);

public static RECT GetClientRect(IntPtr hWnd)
{
    RECT result;
    GetClientRect1(hWnd, out result);
    RECT appRect = result;
    return result;
}

appRect 应该是 RECT 而不是 Rectangle,因为它们属于不同的类型。 RECT 因其结构而起作用:

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
    public int left;
    public int top;
    public int right;
    public int bottom;
}

【讨论】:

  • 这不会改变问题中的代码。您在回答和评论中提到了Rectangle,但代码中缺少它?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-19
  • 2012-10-27
  • 1970-01-01
相关资源
最近更新 更多