【问题标题】:aspx does not contain a definition for this.Boundsaspx 不包含 this.Bounds 的定义
【发布时间】:2012-04-21 20:06:49
【问题描述】:

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

**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?)***

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

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

【问题讨论】:

  • asp.net 运行进程没有屏幕 - 那你想得到什么,管理员桌面背景?或用户背景:) - 下界是可能的。
  • 你好 Aristos,我正在尝试获取单击按钮时显示的屏幕截图。另外,正如我提到的,如果我使用 screen.primary.screen.bounds,我会得到一个截图我当前的桌面
  • 你明确地混淆了你能做什么和不能做什么。您可以做类似事情的唯一方法是使用 javascript 和这个库 stackoverflow.com/questions/2732488/…
  • 我实际上想要实现的是在不使用任何第三方应用程序的情况下截取网页特定区域的屏幕截图并将其保存在系统上。我听说可以通过以下方式实现修改 graphics.copyfromscreen ..但我无法理解如何去做。

标签: asp.net screenshot buttonclick


【解决方案1】:

不可能捕获浏览器、用户、服务器、桌面或其他任何地方的屏幕使用背后的代码。 >

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

【讨论】:

  • 你是说我没有办法实现它:(除了使用 3rd 方工具我的意思是???
  • @nitinvertigo 我是说没有办法,在后面的代码上运行的第 3 方工具可以做你想做的事。使用 javascript 获取屏幕的方法很复杂,但前提是用户使用您提供的功能来执行此操作。
  • @nitinvertigo 你能告诉我们你在这里实际尝试做什么,他们也许我可以提供更多帮助。
  • 感谢您的回复...我正在尝试在网站上导出到 ppt 按钮。该网站包含图表。我的要求是当我单击该按钮时,显示的图表当时在网页上应该以图像的形式导出到 powerpoint 幻灯片。我也可以捕获整个屏幕,但不能捕获特定的图表。
  • 此外,正在显示的图表位于 iframe 内。它还有一个 html 地址。因此,如果您能告诉我任何将 url 的内容捕获为图像的方法,也可以满足我的要求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多