如何在ASP.NET中使用System.Windows.Forms命名空间 [英] How to use System.Windows.Forms Namespace in ASP.NET
本文介绍了如何在ASP.NET中使用System.Windows.Forms命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个用于生成网页快照的源代码.该代码包含WebBrowser类,该类位于名称空间System.Windows.Forms;
下
当我调试代码时,它在ASP.NET网页中将System.Windows.Forms显示为错误.
该怎么办?
这是我在网上找到的代码.
I have a source code for generating the snapshot of a webpage. The code is containing the WebBrowser class which is under the namespace System.Windows.Forms;
When i debug the code, it shows System.Windows.Forms as error in ASP.NET webpage.
What to do?
Here is the code what i found on web.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
namespace WebSiteSnapshotThumbnails
{
public class WebSiteSnapshot
{
#region Private Properties
private String Url { get; set; }
private Int32 BrowserWidth { get; set; }
private Int32 BrowserHeight { get; set; }
private Bitmap Bitmap { get; set; }
#endregion
#region Constructors
public WebSiteSnapshot(string url, int browserWidth, int browserHeight)
{
this.Url = url;
this.BrowserWidth = browserWidth;
this.BrowserHeight = browserHeight;
}
#endregion
#region Public Methods
public Bitmap GenerateWebSiteImage()
{
Thread m_thread = new Thread(new ThreadStart(_GenerateWebSiteImage));
m_thread.SetApartmentState(ApartmentState.STA);
m_thread.Start();
m_thread.Join();
return Bitmap;
}
#endregion
#region Private Methods
private void _GenerateWebSiteImage()
{
WebBrowser m_WebBrowser = new WebBrowser();
m_WebBrowser.ScrollBarsEnabled = false;
m_WebBrowser.Navigate(Url);
m_WebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted);
while (m_WebBrowser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
m_WebBrowser.Dispose();
}
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser m_WebBrowser = (WebBrowser)sender;
m_WebBrowser.ClientSize = new Size(this.BrowserWidth, this.BrowserHeight);
m_WebBrowser.ScrollBarsEnabled = false;
Bitmap = new Bitmap(m_WebBrowser.Bounds.Width, m_WebBrowser.Bounds.Height);
m_WebBrowser.BringToFront();
m_WebBrowser.DrawToBitmap(Bitmap, m_WebBrowser.Bounds);
}
#endregion
}
}
推荐答案
首先,您必须添加对适当程序集的引用.
其次,对控件执行此操作是毫无意义的,因为您实际上无法在网页上使用Windows.Forms程序集中的任何控件.
First, you have to add a reference to the appropriate assembly.
Second, doing this for a control is fairly pointless because you can''t actually use any of the controls in the Windows.Forms assembly on a web page.
让它正常工作,您缺少有关Windows应用程序和Web应用程序的基础知识.我建议您先了解Web应用程序的工作原理.
Leave alone making it work, you are missing the basics about windows application and web application. I would rather suggest you to first understand how a web application works.
System.Windows
中的任何内容都不能在Web应用程序中使用.
System.Windows.Forms是客户端控件.但是,Web应用程序在服务器端运行,并且在System.Web.UI
中具有自己的UI元素.
Nothing inSystem.Windows
is intended to be used in a Web application.
System.Windows.Forms are client controls. However, web applications run on the server side, and have their own UI elements inSystem.Web.UI
.
这篇关于如何在ASP.NET中使用System.Windows.Forms命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文