Vb.net 将PictureBox内容发送到MsPaint

Vb.net 将PictureBox内容发送到MsPaint,vb.net,arguments,picturebox,Vb.net,Arguments,Picturebox,如何发送picturebox的内容以在paint中编辑? 我曾想过快速暂时保存它,然后发送临时地址以加载,但我认为这会导致一些小的保存问题。不幸的是,我现在用C#提供答案。幸运的是,只需更改语法,而不必更改内容 假设这是picturebox控件,将内容(作为位图)放在剪贴板上。现在,您可以将其粘贴到MSPaint中,如果将其设置为前台,则可以使用SendMessage或SendKeys等 Bitmap bmp = new Bitmap(pictureBox1.Image); Clipboard.

如何发送picturebox的内容以在paint中编辑?
我曾想过快速暂时保存它,然后发送临时地址以加载,但我认为这会导致一些小的保存问题。

不幸的是,我现在用C#提供答案。幸运的是,只需更改语法,而不必更改内容

假设这是picturebox控件,将内容(作为位图)放在剪贴板上。现在,您可以将其粘贴到MSPaint中,如果将其设置为前台,则可以使用SendMessage或SendKeys等

Bitmap bmp = new Bitmap(pictureBox1.Image);
Clipboard.SetData(System.Windows.Forms.DataFormats.Bitmap, bmp);
一个糟糕的例子,可选打开mspaint并等待它出现,使用SendKeys进行粘贴

    [DllImport("User32.dll", SetLastError = true)]
    public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);


    private static void TestSendPictureToMSPaint()
    {
        Bitmap bmp = new Bitmap(pictureBox1.Image);
        Clipboard.SetData(System.Windows.Forms.DataFormats.Bitmap, bmp);

        //optional#1 - open MSPaint yourself
        //var proc = Process.Start("mspaint");

        IntPtr msPaint = IntPtr.Zero;
        //while (msPaint == IntPtr.Zero) //optional#1 - if opening MSPaint yourself, wait for it to appear
        msPaint = FindWindowEx(IntPtr.Zero, new IntPtr(0), "MSPaintApp", null);

        SetForegroundWindow(msPaint); //optional#2 - if not opening MSPaint yourself

        IntPtr currForeground = IntPtr.Zero;
        while (currForeground != msPaint)
        {
            Thread.Sleep(250); //sleep before get to exit loop and send immediately
            currForeground = GetForegroundWindow();
        }
        SendKeys.SendWait("^v");
    }

回答我自己的问题只是为了向任何想要一个简单的好例子的人展示我的工作代码

所以用img_图片作为我的图片盒

Dim sendimage As Bitmap = CType(img_picture.Image, Bitmap)
Clipboard.SetDataObject(sendimage)
Dim programid As Integer = Shell("mspaint", AppWinStyle.MaximizedFocus)
System.Threading.Thread.Sleep(100)
AppActivate(programid)
SendKeys.Send("^v")
如果没有线程暂停,AppActivate将出现一个错误,声称没有这样的进程存在


感谢布兰德的帮助。

太好了。我花了一秒钟的时间才弄明白为什么找不到应用程序id,但一个小的线程暂停修复了它。非常好,谢谢。