Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#剪断工具服务_C#_.net_Winforms - Fatal编程技术网

C#剪断工具服务

C#剪断工具服务,c#,.net,winforms,C#,.net,Winforms,首先,这个问题是为了教育目的 我的任务是做一项服务,像截图工具一样捕捉屏幕的某些部分 Win7我设法以win的形式实现了这一点,它的工作非常出色,但是当我在服务中实现它时,它会返回一个黑屏,我知道问题是服务在不同的会话中运行,所以我的问题是如何使服务运行并返回用户桌面 第二个问题是如何在服务中收听按键(我知道如何在表单中进行)请提供帮助。慢慢来。我的表格代码: private void CaptureScreen() { this.Hide(); Thread.Sleep(300

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

我的任务是做一项服务,像截图工具一样捕捉屏幕的某些部分 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);
    }
}
private void CaptureScreen()
{
this.Hide();
睡眠(300);
bmpScreenshot=新位图(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();
}
私有静态图像复制(位图图像、矩形复制)
{
位图bmpCrop=img.Clone(cropArea,
像素格式);
返回(图像)(bmpCrop);
}
专用矩形选择区域(int-recX1、int-recY1、int-recX2、int-recY2)
{
int width=recX2-recX1;
内部高度=recY2-recY1;
返回新矩形(recX1,recY1,宽度,高度);
}
私有无效btnCrop_单击(对象发送方,事件参数e)
{

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


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


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

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


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

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

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


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

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


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


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

请编辑问题并添加大写字母、句点和其他标点符号,如问号。@Erno:我做了一些尝试来解决这一问题,这取决于操作系统。这在Windows服务器上永远不会起作用。请编辑问题并添加大写字母、句点和其他标点符号,如问号。@Erno:I-did一些人试图修复依赖于操作系统的问题。这在Windows服务器上永远不会起作用。我喜欢这个想法,但如何制作这样的东西你可以制作一个经典的Windows应用程序。在运行时,你可以将
WindowState
更改为Minimized,将ShowInTaskBar更改为false。我喜欢这个想法,但如何制作这样的东西你可以制作一个经典的Windows应用程序nning时,将
WindowState
更改为Minimized,将ShowInTaskBar更改为false。