这是我设法写的东西:
private void SetSizeableCore(bool value)
{
fSizeable = value;
if (value)
{
FormBorderStyle = FormBorderStyle.SizableToolWindow;
DockPadding.All = 0;
System.Version ver = Environment.OSVersion.Version;
// Always for WinXP family, but for higher systems only if the aero theme is not in effect
bool needShadow = ((ver.Major == 5) && (ver.Minor > 0)) || ((ver.Major > 5) && !IsAeroThemeEnabled());
SetShadowFlag(needShadow);
}
else
{
FormBorderStyle = FormBorderStyle.None;
DockPadding.All = 1;
SetShadowFlag(true);
}
}
private void SetShadowFlag(bool hasShadow)
{
if (!IsDropShadowSupported())
return;
System.Runtime.InteropServices.HandleRef myHandleRef = new System.Runtime.InteropServices.HandleRef(this, this.Handle);
int myStyle = iGNativeMethods.GetClassLongPtr(myHandleRef, iGNativeMethods.CS_DROPSHADOW).ToInt32();
if (hasShadow)
myStyle |= iGNativeMethods.CS_DROPSHADOW;
else
myStyle &= ~iGNativeMethods.CS_DROPSHADOW;
iGNativeMethods.SetClassLong(myHandleRef, iGNativeMethods.GCL_STYLE, new IntPtr(myStyle));
}
private bool IsDropShadowSupported()
{
// Win2000 does not have this feature
if (Environment.OSVersion.Version <= new Version(5, 0))
return false;
bool myResult = false;
iGNativeMethods.SystemParametersInfo(iGNativeMethods.SPI_GETDROPSHADOW, 0, ref myResult, 0);
return myResult;
}
private bool IsAeroThemeEnabled()
{
if (Environment.OSVersion.Version.Major > 5)
{
bool aeroEnabled;
iGNativeMethods.DwmIsCompositionEnabled(out aeroEnabled);
return aeroEnabled;
}
return false;
}
如我错了请纠正我。