2009-07-24 7 views

答えて

2

フォームのDesktopBoundsプロパティを試してください。

+0

'FormBorderStyle'が' FixedToolWindow'の場合、 'DesktopBounds'は' Size'よりも良い答えではないと思います。私は、Aeroが有効になっていると、両方が間違っていると思う。 –

2

サイズプロパティは間違いなく機能するはずです。デザイン・マシンとプロダクション・マシンの間のシステム・フォントまたはビデオ・アダプターのDPI設定の違いにより、フォームが再スケーリングされる可能性があることに注意してください。実際のサイズはLoadイベントまで使用できません。

0

Aeroが有効で、FormBorderStyleFixedToolWindowの場合、Windowsではフォームのサイズが表示されます。私はFormの次のコードは、そのようなウィンドウの正しい高さと幅を与えると思います。

[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; 
} 
関連する問題