簡體   English   中英

如何直接使用C#引用Paint.NET程序集

[英]How to reference the Paint.NET assemblies directly using C#

我想直接引用Paint.NET程序集,並以這種方式使用其功能。 我不知道如何使用.dll文件PaintDotNet.Core.dll並在C#visual studio中使用它的功能沒有任何幫助。

要引用這些程序集:C:\\ Program Files \\ Paint.NET \\ PaintDotNet。*。dll然后在這些命名空間中的類周圍戳一下。

代碼:

  private void button2_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    string filename = "";

    if (ofd.ShowDialog() == DialogResult.OK)
    {
        filename = System.IO.Path.GetFullPath(ofd.FileName);
    }
   // MessageBox.Show(filename, "file");
    pictureBox1.ImageLocation = filename;
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

    DialogResult result = MessageBox.Show("Do you wish to continue?", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (result == DialogResult.Yes)
    {
        System.Diagnostics.Process.Start(@"C:\Program Files\Paint.NET\PaintDotNet.exe");
       // here i need to perform the function like
       //Open + O`
       //ctrl + Shift + L)` then `
       //(ctrl + Shift + G)`. then save 
       //`ctrl + Shift + S`
    }
    else
    {
        return;
    }
}

只需將一個或一些或所有庫添加到您的項目。 作為測量狀態,然后使用對象資源管理器。

注意:不用管.xaml內容或我試圖在wpf應用程序中渲染SharpDX D3D11來制作地圖編輯器的實際項目(並且沒有工具包(不要問我為什么。我瘋了))。

我發誓我昨晚有代碼,您是否正在嘗試使paint.net自動化? 您將必須制作一個插件,該插件將比不必啟動第二個應用程序更簡化流程。

vs2012屏幕截圖

只需按照說明將快捷鍵發送到另一個應用程序

將此命名空間添加到類中

using System.Runtime.InteropServices;

然后使用DllImport語句聲明SetForegroundWindow函數。 這將創建已在User32.dll創建的方法的對象

[DllImport ("User32.dll")]
static extern int SetForegroundWindow(IntPtr point);

並將以下代碼添加到您的按鈕單擊或項目中的任何位置。 此代碼將導航OpenFileDialog以在Paint.NET應用程序中打開現有文件。

private void button1_Click(object sender, EventArgs e)
{
    Process p = Process.GetProcessesByName("PaintDotNet").FirstOrDefault();
    if (p != null)
    {
        SetForegroundWindow(p.MainWindowHandle); //Set the Paint.NET application at front
        SendKeys.SendWait("^(o)"); //^(o) will sends the Ctrl+O key to the application. 
    }
}

大多數程序員使Ctrl+OCtrl+o之間的錯誤看起來相似,但是兩個鍵的ascii值不同。 因此,請確保關鍵字符不是大寫。 您還可以在msdn上閱讀有關SendKey方法的完整信息。 您可以進行任何組合鍵並通過SendWait()方法發送。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM