【问题标题】:C# snipping tool serviceC# 截图工具服务
【发布时间】:2011-01-26 17:48:56
【问题描述】:

首先这个问题是为了教育目的。

我的任务是提供捕获屏幕选择部分的服务,例如截图工具 Win7我设法以win形式做到这一点并且它的工作很好但是当我在服务中这样做时它返回一个黑屏我知道问题是服务在不同的会话中运行所以我的问题是如何使服务运行和返回用户桌面 第二个问题是如何在服务中收听按键(我知道如何在表格中做到这一点)请提供任何帮助。慢慢来。我的表单代码:

private void CaptureScreen()
{
    this.Hide();
    Thread.Sleep(300);
    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
    gfxScreenshot = Graphics.FromImage(bmpScreenshot);
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
    bmpScreenshot.Save(DialogSave.FileName, ImageFormat.Jpeg);

    pictureBox1.Image = bmpScreenshot;
    this.Show();
}

private static Image cropImage(Bitmap img, Rectangle cropArea)
{
    Bitmap bmpCrop = img.Clone(cropArea,
    img.PixelFormat);
    return (Image)(bmpCrop);
}

private Rectangle selectArea(int recX1, int recY1,int recX2,int recY2) 
{
    int width = recX2 - recX1;
    int height = recY2 - recY1;
    return new Rectangle(recX1, recY1, width, height);
}

private void btnCrop_Click(object sender, EventArgs e)
{
    if (x1 <= 0 || x2 <= 0 || y1 <= 0 || y2 <= 0)
    {
        MessageBox.Show("Please select area first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    else
    {
        Rectangle myrectangle = selectArea(x1, y1, x2, y2);
        Bitmap myImg = (Bitmap)Image.FromFile(filename);
        Image cr = cropImage(myImg, myrectangle);
        na = @"F:\\" + Counter + ".jpg";
        while (File.Exists(@"F:\\" + Counter + ".jpg"))
        {
            Counter++;
        }
        na = @"F:\\" + Counter + ".jpg";
        cr.Save(@"F:\\" + Counter++ + ".jpg", ImageFormat.Jpeg);
        pictureBox1.Image = cr;
        System.Diagnostics.Process prc = new System.Diagnostics.Process();
        prc.StartInfo.FileName = @"F:\\";
        prc.Start();
        this.PrintScreennotifyIcon.BalloonTipText = "Save to" + na;
        this.PrintScreennotifyIcon.BalloonTipTitle = "Info";
        this.PrintScreennotifyIcon.Visible = true;
        this.PrintScreennotifyIcon.ShowBalloonTip(3);
    }
}

【问题讨论】:

  • 请编辑问题并添加大写、句点和其他标点符号,例如问号。
  • @Erno:我做了一些尝试来解决这个问题
  • 取决于操作系统。这永远不会在 Windows 服务器上工作。

标签: c# .net winforms


【解决方案1】:

在某些版本的 Windows 上,您可以让服务查看桌面,但是如果有多人登录,它应该选择哪个桌面?

基本上,如果您想与桌面进行属性交互,您的解决方案不能作为服务运行。

此外,出于同样的原因,您不应生成消息框,因为可能没有人可以单击“确定”并允许程序继续执行。

【讨论】:

    【解决方案2】:

    您必须选中“允许服务与桌面交互”选项并选择本地帐户(服务屏幕上的所有内容)。

    【讨论】:

      【解决方案3】:

      对我来说,最简单的方法是让正在运行的应用程序在任务栏中最小化并在计算机启动时启动。

      它对计算机的干扰真的很小:)。

      【讨论】:

      • 我喜欢这个想法,但如何做到这一点
      • 你制作了一个经典的 Windows 应用程序'。运行时,将 WindowState 更改为 Minimized 并将 ShowInTaskBar 更改为 false。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 2011-08-01
      • 2014-07-02
      相关资源
      最近更新 更多