如何在ASP.NET中使用按钮单击调用类

如何在ASP.NET中使用按钮单击调用类,asp.net,Asp.net,我有一个类需要在Asp.Net中单击按钮时调用。该类用于录制屏幕并将录制的文件保存在桌面中 这是需要调用的类 public class ScreenRecorder { private static string tempDir = Path.GetTempPath() + "/snapshot/"; private static System.Threading.Thread snap = new System.Threading.Thread(Snapshot); private

我有一个类需要在Asp.Net中单击按钮时调用。该类用于录制屏幕并将录制的文件保存在桌面中

这是需要调用的类

    public class ScreenRecorder
{

private static string tempDir = Path.GetTempPath() + "/snapshot/";
private static System.Threading.Thread snap = new System.Threading.Thread(Snapshot);

private static System.Drawing.Rectangle _Bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
public static System.Drawing.Rectangle Bounds
{
    get { return _Bounds; }
    set { _Bounds = value; }
}

private static void Snapshot()
{
    if (!Directory.Exists(tempDir))
        Directory.CreateDirectory(tempDir);
    int Co = 0;
    do
    {
        Co += 1;
        System.Threading.Thread.Sleep(50);
        System.Drawing.Bitmap X = new System.Drawing.Bitmap(_Bounds.Width, _Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
        using(System.Drawing.Graphics G = System.Drawing.Graphics.FromImage(X)) {
            G.CopyFromScreen(_Bounds.Location, new System.Drawing.Point(), _Bounds.Size);
            System.Drawing.Rectangle CurBounds = new System.Drawing.Rectangle(System.Drawing.Point.Subtract(System.Windows.Forms.Cursor.Position,Bounds.Size), System.Windows.Forms.Cursor.Current.Size);
            System.Windows.Forms.Cursors.Default.Draw(G, CurBounds);
       }
        System.IO.FileStream FS = new System.IO.FileStream(tempDir + FormatString(Co.ToString(), 5, '0') + ".png", System.IO.FileMode.OpenOrCreate);
        X.Save(FS, System.Drawing.Imaging.ImageFormat.Png);
        X.Dispose();
        FS.Close();
    } while (true);
}

public static void ClearRecording()
{
    if (Directory.Exists(tempDir))
        Directory.Delete(tempDir, true);
        Directory.CreateDirectory(tempDir);
}

public static void Save(string Output)
{
    System.Windows.Media.Imaging.GifBitmapEncoder G = new System.Windows.Media.Imaging.GifBitmapEncoder();

    List<System.IO.FileStream> X = new List<System.IO.FileStream>();
    foreach (string Fi in Directory.GetFiles(tempDir, "*.png", SearchOption.TopDirectoryOnly))
    {
        System.IO.FileStream TempStream = new System.IO.FileStream(Fi, System.IO.FileMode.Open);
        System.Windows.Media.Imaging.BitmapFrame Frame = System.Windows.Media.Imaging.BitmapFrame.Create(TempStream);
        X.Add(TempStream);
        G.Frames.Add(Frame);
    }
    System.IO.FileStream FS = new System.IO.FileStream(Output, System.IO.FileMode.OpenOrCreate);
    G.Save(FS);
    FS.Close();

    foreach (System.IO.FileStream St in X)
    {
        St.Close();

    }

}

public static void Start()
{
    snap = new System.Threading.Thread(Snapshot);
    snap.Start();
}

public static void Stop()
{
    snap.Abort();
}

private static string FormatString(string S, int places, char character)
{
    if (S.Length >= places)
        return S;
    for (int X = S.Length; X <= places; X++)
    {
        S = character + S;
    }
    return S;
}

}

class Program
{
   static void Main(string[] args)
    {
    ScreenRecorder.Start();
    System.Threading.Thread.Sleep(5000);
    ScreenRecorder.Stop();
    ScreenRecorder.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\video.gif");
    ScreenRecorder.ClearRecording();
   }
  }
公共类屏幕记录器
{
私有静态字符串tempDir=Path.GetTempPath()+“/snapshot/”;
private static System.Threading.Thread snap=新系统.Threading.Thread(快照);
私有静态System.Drawing.Rectangle _Bounds=System.Windows.Forms.Screen.PrimaryScreen.Bounds;
公共静态System.Drawing.Rectangle边界
{
获取{return\u Bounds;}
设置{u Bounds=value;}
}
私有静态void快照()
{
如果(!Directory.Exists(tempDir))
CreateDirectory(tempDir);
int Co=0;
做
{
Co+=1;
系统.线程.线程.睡眠(50);
System.Drawing.Bitmap X=新的System.Drawing.Bitmap(_Bounds.Width、_Bounds.Height、System.Drawing.Imaging.PixelFormat.Format32bppArgb);
使用(System.Drawing.Graphics G=System.Drawing.Graphics.FromImage(X)){
G.CopyFromScreen(_Bounds.Location,new System.Drawing.Point(),_Bounds.Size);
System.Drawing.Rectangle路缘=新的System.Drawing.Rectangle(System.Drawing.Point.Subtract(System.Windows.Forms.Cursor.Position,Bounds.Size),System.Windows.Forms.Cursor.Current.Size);
System.Windows.Forms.Cursors.Default.Draw(G,路缘);
}
System.IO.FileStream FS=new System.IO.FileStream(tempDir+FormatString(Co.ToString(),5,'0')+“.png”,System.IO.FileMode.OpenOrCreate);
保存(FS,System.Drawing.Imaging.ImageFormat.Png);
X.处置();
FS.Close();
}虽然(正确);
}
公共静态无效ClearRecording()
{
if(Directory.Exists(tempDir))
Delete(tempDir,true);
CreateDirectory(tempDir);
}
公共静态无效保存(字符串输出)
{
System.Windows.Media.Imaging.GifBitmapEncoder G=新的System.Windows.Media.Imaging.GifBitmapEncoder();
列表X=新列表();
foreach(Directory.GetFiles(tempDir,*.png,SearchOption.TopDirectoryOnly)中的字符串Fi)
{
System.IO.FileStream TempStream=new System.IO.FileStream(Fi,System.IO.FileMode.Open);
System.Windows.Media.Imaging.BitmapFrame Frame=System.Windows.Media.Imaging.BitmapFrame.Create(TempStream);
X.Add(TempStream);
G.框架。添加(框架);
}
System.IO.FileStream FS=new System.IO.FileStream(输出,System.IO.FileMode.OpenOrCreate);
G.Save(FS);
FS.Close();
foreach(X中的System.IO.FileStream St)
{
圣克洛斯();
}
}
公共静态void Start()
{
snap=新系统.Threading.Thread(快照);
snap.Start();
}
公共静态无效停止()
{
snap.Abort();
}
私有静态字符串FormatString(字符串S、整数位置、字符)
{
如果(S.Length>=位置)
返回S;

对于(int X=S.Length;X您在
Main
中的内容被称为调用。此类用于桌面应用程序。您似乎希望在远程用户浏览您的网站时记录其屏幕?调用类并不意味着任何事情。您需要调用类的方法/函数来获取类的行为。与Main方法y类似您已调用ScreenRecorder.Start();或其他方法。实际上,上面的代码是一个控制台应用程序。我正在asp.net中运行web应用程序!!那么如何通过按钮单击调用它???@naveenI我只是想录制屏幕,所以我尝试了这个方法。有没有办法?asp.net代码中包含什么软件?就像在页面加载后播放音乐的播放器一样??@CyberDude