aspx不包含this.Bounds的定义

时间:2012-04-09 12:47:07

标签: asp.net screenshot buttonclick

大家好我正在编写一个程序,当点击一个按钮时,该程序会捕获部分屏幕。以下是我的代码

**default.aspx**
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="_9marchexp._Default" %>

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <h2>
            Welcome to ASP.NET!
        </h2>
        <p>
            To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
        </p>
        <p>
            You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
                title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
        </p>
        <p>
            &nbsp;</p>
        <p>
            &nbsp;</p>
        <p>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        </p>
    </asp:Content>

default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

namespace _9marchexp
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            Rectangle formRect = this.Bounds; // saving information aout your window in formRect <br/>
                       // (height, width, x, y, etc

      using (Bitmap bitm = new Bitmap(formRect.Width, formRect.Height)) // creating new bitmap of the same <br/>
                                       // height and width as our own window
      {
        using (Graphics graphic = Graphics.FromImage(bitm))
        {
          graphic.CopyFromScreen(new Point(formRect.Left, formRect.Top), Point.Empty, formRect.Size);
        }
        bitm.Save("C:\\Users\\xxxx\\Desktop\\myscreenshot.jpg", ImageFormat.Jpeg); // saving the bitmap bile to destination dir. <br/>
                               // with specified name


        }
    }
    }
}

但是,当我执行代码时,会显示错误消息

***'_9marchexp._Default' does not contain a definition for 'Bounds' and no extension method 'Bounds' accepting a first argument of type '_9marchexp._Default' could be found (are you missing a using directive or an assembly reference?)***

如何纠正,有人可以帮助我吗?

如果我用 Screen.PrimaryScreen.Bounds 替换 this.Bounds ,代码运行完美,但整个屏幕的屏幕截图都是我不想要的。

1 个答案:

答案 0 :(得分:1)

无法捕捉浏览器,用户,服务器或桌面的屏幕,或者使用背后的代码。 >

可以在此处找到读取页面并将其打印到图像的解决方案 Convert webpage to image from ASP.NET