WpF arabirimimin konumunu almak istiyorum. Bu kod C# 2.0'da çalışabilir, ancak C# 4.0'da bir hata bildirin. Kod budur.C# 4.0 wpf'de GetWindowRect
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(HandleRef hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
Rectangle myRect = new Rectangle();
private void button1_Click(object sender, System.EventArgs e)
{
RECT rct;
if(!GetWindowRect(new HandleRef(this, this.Handle), out rct)) //Here is the error
{
MessageBox.Show("ERROR");
return;
}
MessageBox.Show(rct.ToString());
myRect.X = rct.Left;
myRect.Y = rct.Top;
myRect.Width = rct.Right - rct.Left + 1;
myRect.Height = rct.Bottom - rct.Top + 1;
}
neyi ** olduğunu ** hata kodu? – Stormie
Hata nedir? – krlzlx
Hata "Tutamaç" tanımına dahil değildir. – HaoHuaqing