vb.net - 将 PictureBox 内容发送到 MsPaint

标签 vb.net arguments picturebox

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

最佳答案

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

假设这是您的图片框控件,获取内容(作为位图)并将其放在剪贴板上。现在,您可以将其粘贴到 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");
    }

关于vb.net - 将 PictureBox 内容发送到 MsPaint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16072215/

相关文章:

c# - 如何从 JToken 填充现有对象(使用 Newtonsoft.Json)?

c# - 验证函数参数?

Java:将一个ImageIcon设置为等于另一个

c++ - 在本地修改的按值传递的参数会发生什么情况?

c++ - 在图片框中以 cv::Mat 格式显示网络摄像头提要

c# - 如何在另一种方法中使用 MouseEventArgs?

c# - 同时接收 PictureBox 和 DataGridViewImageCell 的函数

vb.net - 为什么 Visual Studio 2012 不允许您在创建新的 VB.NET 文件时选择结构?结构是否已弃用?

c# - SeDebugPrivilege() api 函数是否与 System.Diagnostics.Process.EnterDebugMode 相同?

.net - VB.NET: bool 值来自 `Nothing` 有时是 `false` 有时是 Nullreference-Exception