0

I wanted to reference the Paint.NET assemblies directly and use a its functionality that way. i dont know how to use the .dll file PaintDotNet.Core.dll and use it functionality in C# visual studio any helps. Please

want to reference to these assemblies: C:\Program Files\Paint.NET\PaintDotNet.*.dll Then poke around the classes in those namespaces.

Codes:-

  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;
    }
}
Community
  • 1
  • 1
Stacy Kebler
  • 180
  • 1
  • 3
  • 22
  • The code you posted doesn't seem to use the reference. Have you tried referencing it in your Visual Studio Solution->Project? If you want to automate the program, you could try loading the program inside yours with Assembly.Load() and then running the entry point of the MainModule. I don't know anything about Paint.NET though. – Measurity Oct 09 '14 at 20:48
  • 1
    As far as I know, paintdotnet doesn't have an API which is meant for external use. They only offer development of plugins which work within the scope of the main paintdotnet application. – Vlad Oct 09 '14 at 20:55
  • 1
    For such macros (sequence of keys to make some automatic operation) you do not need C#. Just use some dedicated tool like [AutoHotKey](http://www.autohotkey.com). – Konrad Kokosa Oct 09 '14 at 20:58
  • @KonradKokosa ok i saw this.. but how can i open image using these.. convert to bmp file using this autohotkey – Stacy Kebler Oct 09 '14 at 23:36
  • @KonradKokosa actually i checked the autohotkey.. we need to press any key to activate this right.. where i don't like to press any key.. the moment it get activated.. it should start doing.. seems crazy rite.. i know.. but i need in this way.. – Stacy Kebler Oct 09 '14 at 23:52
  • I don't think that dll gives any kind of feature to call the function from outside the application. if you are trying to fire the Open File Or Save file event from outside the application then I don't think that is possible. yeah, but you can send any shortcut keys to another application by making that application at foreground and send the shortcut key sequence by using `Send.SendWait()` method. You can read this post for more information http://stackoverflow.com/a/15292428/3761928 – Shell Oct 23 '14 at 02:30
  • @Shell yes excatly shell. I need to run the apalication. then i need to send these key.. //Open + O` //ctrl + Shift + L)` then ` //(ctrl + Shift + G)`. then save //`ctrl + Shift + S`.. This was the one i was looking for.. Thanks a lot – Stacy Kebler Oct 23 '14 at 12:41

2 Answers2

1

Just add one or some or all of the libraries to your project. as Measuring states then use the object explorer.

NOTE: never mind the .xaml stuff or the actual projects I am trying to render SharpDX D3D11 in a wpf app to make a map editor (and without the toolkit (don't ask me why. I am crazy)).

I swear I have the code last night are you trying to automate paint.net? you will have to make a plug-in which would make the process way more streamlined than having to start a second app.

vs2012 screen shot

RadioSpace
  • 953
  • 7
  • 15
  • i already added the references.. tell me how to activate.. these functions of .net paint.. nobody is telling that :-( – Stacy Kebler Oct 09 '14 at 23:40
  • after opening the paint i need to do these functions.. thats it.. //Open + O` `//ctrl + Shift + L)` then ` `//(ctrl + Shift + G)`. then save `//`ctrl + Shift + S`.. save as.. .`pcx file type.. :-) – Stacy Kebler Oct 09 '14 at 23:41
  • 1
    well I doubt you will find the proper documentation. but you can guess the rest of your life away. after you reference a library to your project place `using somenamespace` namespaces are listed under where you see PaintDotNet.Base. now try and instantiate whatever you can get your hands on. now realize that you are barking up the wrong tree. what you really want to do is emulate a keyboard that sends commands to whatever has focus. but maybe it would first check to see if paintdotnet has focus. if true. the keyboard emulator just sends the OS input. as Konrad said in your question comments 12 – RadioSpace Oct 09 '14 at 23:52
  • can you help me automatically convert a .png file to .GRF file.. that's all i need.. can you help programatically.. please – Stacy Kebler Oct 09 '14 at 23:54
  • 1
    do you have a link to the specification for a GRF file. frankly I have not heard of that. but PNG are easily loaded into memory Via a call to `SharpDX.Direct3D11.Texture2D.FromFile`. – RadioSpace Oct 10 '14 at 00:00
  • 1
    @StacyKebler is this the GRF you are talking about? [GRAPH](http://en.wikipedia.org/wiki/GraphEdit) – RadioSpace Oct 10 '14 at 00:03
  • hehehe..... yes.. i will show you.. its like.. lets say.. i draw a line in a paint... then.. if i convert to grf it looks like.. https://imageshack.com/i/f0sKfg2Rp the black part looks with letter F rest every thing.. white will be zero – Stacy Kebler Oct 10 '14 at 00:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62789/discussion-between-stacy-kebler-and-radiospace). – Stacy Kebler Oct 10 '14 at 00:10
  • 1
    @StacyKebler have you seen this? [zebra question](http://stackoverflow.com/questions/14054626/how-to-generate-a-dynamic-grf-image-to-zpl-zebra-print) – RadioSpace Oct 10 '14 at 00:28
1

Just follow the instruction to send the shortcut key to another application

Add this namespace to the class

using System.Runtime.InteropServices;

Then declare SetForegroundWindow function with DllImport statement. this will create object of that method which has been created in User32.dll

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

And add the following code to your button click or anywhere in your project. This code will navigate the OpenFileDialog to open the existing file in Paint.NET application.

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. 
    }
}

most of programmers made the mistake between Ctrl+O and Ctrl+o seems similar but, the ascii value of both key is different. So, make sure the key character is not in uppercase. You can also read the full information about SendKey method on msdn. You can make any key combination and send through the SendWait() method.

Shell
  • 6,818
  • 11
  • 39
  • 70