2009-07-24 3 views

답변

2

폼의 DesktopBounds 속성을 사용해보십시오.

+0

'FormBorderStyle'이 FixedToolWindow 인 경우, 'DesktopBounds'가 'Size'보다 더 나은 대답을 제공한다고 생각하지 않습니다. Aero가 활성화되어 있으면 두 가지 모두 올바르지 않다고 생각합니다. –

2

크기 속성이 올바르게 작동해야합니다. 디자인 시스템과 프로덕션 시스템 사이의 시스템 글꼴 또는 비디오 어댑터 DPI 설정의 차이로 인해 양식이 재조정 될 수 있습니다. 실제 크기는 Load 이벤트까지 사용할 수 없습니다.

0

에어로를 사용하고 FormBorderStyleFixedToolWindow 인 경우 Windows에서 양식의 크기를 알 수 있습니다. 나는 Form에있는 다음 코드가 그러한 Window의 정확한 높이와 너비를 제공한다고 생각합니다.

[DllImport("dwmapi.dll", PreserveSig = false)] 
public static extern bool DwmIsCompositionEnabled(); 

// When Aero is enabled, and our FormBorderStyle is FixedToolWindow, 
// Windows will lie to us about our size and position. 
public bool AeroIsMessingWithUs() 
{ 
    bool ret = false; 

    // check for other Fixed styles here if needed 
    if (FormBorderStyle == System.Windows.Forms.FormBorderStyle.FixedToolWindow) 
    { 
     if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled()) 
     { 
      // Aero is enabled 
      ret = true; 
     } 
    } 
    return ret; 
} 

public int MyWindowHeight() 
{ 
    int height = Height; 
    if (AeroIsMessingWithUs()) 
    { 
     // there are actually 5 more pixels on the top and bottom 
     height += 10; 
    } 
    return height; 
} 

public int MyWindowWidth() 
{ 
    int width = Width; 
    if (AeroIsMessingWithUs()) 
    { 
     // there are 5 more pixels on the left and right 
     width += 10; 
    } 
    return width; 
} 
관련 문제