1
當我使用航空玻璃運行我的程序時,出現「價值不符合預期範圍」錯誤。我正在使用dwmapi.dll。這是代碼:價值不符合dwmapi.dll的預期範圍
ON Aero.cs
[StructLayout(LayoutKind.Sequential)]
public struct Margins
{
public int Left;
public int Right;
public int Top;
public int Bottom;
}
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref Margins margins);
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();
ON AddStudent.cs
private const int PaddingCounter = 0;
private Aero.Margins _newMargins;
private void SetGlassArea()
{
if (Aero.DwmIsCompositionEnabled())
{
_newMargins.Top = Padding.Top;
_newMargins.Bottom = Padding.Bottom;
_newMargins.Left = Padding.Left;
_newMargins.Right = Padding.Right;
Aero.DwmExtendFrameIntoClientArea(this.Handle, ref _newMargins);
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaint(e);
if (Aero.DwmIsCompositionEnabled())
{
e.Graphics.Clear(Color.Black);
Rectangle clientArea = new Rectangle(_newMargins.Left, _newMargins.Top, this.ClientRectangle.Width - _newMargins.Left -_newMargins.Right,
this.ClientRectangle.Height - _newMargins.Top - _newMargins.Bottom);
Brush b = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(b, clientArea);
}
}
public void ApplyGlassSurface()
{
this.Padding = new Padding(PaddingCounter);
SetGlassArea();
Invalidate();
}
private void AddStudent_Load(object sender, EventArgs e)
{
ApplyGlassSurface();
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo videoCaptureDevice in webcam)
{
comboBoxEx1.Items.Add(videoCaptureDevice.Name);
}
comboBoxEx1.SelectedIndex = 0;
}
錯誤點:
Aero.DwmExtendFrameIntoClientArea(this.Handle, ref _newMargins);
能否請你告訴我什麼是它錯了嗎?我知道它應該工作,因爲我已經看過一個視頻,併爲他工作。謝謝!
你似乎不訴諸文件一併構成該代碼。有很多錯誤。閱讀文檔,然後重試。一個MCVE會很有用。系統告訴你,你的輸入是錯誤的。但是你沒有向我們展示你的意見。而且您不檢查錯誤,因此我無法看到報告的錯誤來自哪裏。我敢打賭,你的真實代碼與你展示的代碼不同。總之這個問題嚴重不足。 –