2016-04-15 46 views
0

我不斷收到兩個「不一致可訪問性」錯誤,指出「...比方法更難以訪問......」。儘管類公衆不一致的可訪問性

我已經找到了解決這個問題的辦法,每個答案基本上都是「讓班級公開。」

我因此被卡住了,因爲班級已經公開了。

這是發生在哪裏的錯誤:

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

閱讀整個錯誤消息。這可能是抱怨'RECT'。 – SLaks

+0

你是對的。我將它改爲矩形,現在沒問題。 – Jillinger

回答

0

好吧,我知道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; 
} 
+1

這不會改變任何問題中的代碼。你在你的回答和評論中提到了'Rectangle',但是它從代碼中缺失了嗎? –

相關問題