문제

I am creating a application which can capture the screen which is selected by current active windows form and make user aware by setting it as the background of it. Please refer the image

enter image description here

But my problem is i cant get the size of the active window size. This is the code i have been working on

 private void button5_Click(object sender, RoutedEventArgs e)

    {
        Image b = null;
        int w = (int)this.Width;
        int h = (int)this.Height;
        **System.Drawing.Size sz = this.Size;
        System.Drawing.Point loc = this.Location;**
        Hide();
        System.Threading.Thread.Sleep(500);
        using (b = new Bitmap(w, h))
        {
            using (Graphics g = Graphics.FromImage(b))
            {
                g.CopyFromScreen(loc, new System.Drawing.Point(0, 0), sz);
            }

            Image x = new Bitmap(b);

            ImageBrush myBrush = new ImageBrush();
            x.Save(@"C:\Users\DZN\Desktop\testBMP.jpeg", ImageFormat.Jpeg);
            myBrush.ImageSource = new BitmapImage(new Uri(@"C:\Users\DZN\Desktop\testBMP.jpeg", UriKind.Absolute));
            this.Background = myBrush;

        }
        Show();
    }

In the bolded lines i get the error saying WpfApplication1.MainWindow' does not contain a definition for 'Size, location. but this works well in windows forms. Any help is hugly appreciated. Thank you.

도움이 되었습니까?

해결책

WPF Window doesn't have a size property instead you can use ActualWidth and ActualHeight. Same way it doesn't exposes Location also but you can use Left and Top properties.

All the above properties are of type double so you need a cast to appropriate type.

System.Drawing.Size sz = new System.Drawing.Size((int)ActualWidth, (int)ActualHeight);
System.Drawing.Point loc = new System.Drawing.Point((int)Left, (int)Top);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top