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